zeldangit
zeldangit

Reputation: 45

Trouble with sum.ml from Real World Ocaml

I'm currently working my way through Real World Ocaml and I got stuck running the OCaml "corebuild" compiled version of sum.ml:

$ ./sum.native 
1
2
3

Uncaught exception:

  (Invalid_argument "Float.of_string ")

Raised at file "pervasives.ml", line 31, characters 25-45
Called from file "sum.ml", line 7, characters 44-61
Called from file "sum.ml", line 10, characters 24-46

What am I doing wrong?

Thank you!

Upvotes: 2

Views: 165

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66818

When I try to recreate your reported error, I don't see it. Things work fine and I get the answer of 6.0. Possibly I'm using a different version of Core.

Update

The problem occurs if you type an extra newline after the last number. Float.of_string fails when the input string is empty. I think that's what you're seeing because there is an empty line between the last number and the error report. If you type ^D to terminate the input, there's no empty line.

Upvotes: 6

Related Questions