1
votes

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?

1

1 Answers

2
votes

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