Having a really hard time figuring out what is wrong with my function, even with the help of the ocaml.org docs.
let dist (x1, y1) (x2, y2) =
let x = (x2 - x1)^2 in
let y = (y2 - y1)^2 in
(x + y) ^ (.5);; //line 13
And I'm getting
File "ish.ml", line 13, characters 12-13:
Error: Syntax error
What is going on?
Pascal Cuoq
80.7k8 gold badges168 silver badges293 bronze badges
asked Feb 9, 2014 at 0:25
Collin
1,9176 gold badges28 silver badges44 bronze badges
1 Answer 1
You need to write floating constants with at least one digit before the decimal point.
Note that in OCaml ^ is a string operation, not exponentiation. You can use ** for exponentiation:
# ( ** );;
- : float -> float -> float = <fun>
# 3.0 ** 0.5;;
- : float = 1.73205080756887719
answered Feb 9, 2014 at 0:37
Jeffrey Scofield
67k2 gold badges77 silver badges110 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
lukstafi
And other float operators with a dot:
let x = (x2 -. x1)**2.0 inlang-ml