1

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

And other float operators with a dot: let x = (x2 -. x1)**2.0 in

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.