2
votes

I have just started learning SML and still in the process of making sense of its error messages.

when trying to input the function definition below

val rec : real->real = fn 0.0 => 0.0 | n:real => 1.0/n;

i get the following error :

stdIn:25.9-25.17 Error: syntax error: deleting  COLON ID ARROW
stdIn:25.24-25.33 Error: syntax error: deleting  FN REAL DARROW
stdIn:25.38 Error: syntax error found at BAR

can someone point out what i am doing wrong ?

thank you.

1

1 Answers

4
votes

You have two errors in your code:

  1. Between val rec and the type annotation there should be the name of the value you're defining.
  2. You can't use pattern matching on reals. Since reals are inexact, they aren't equality types, so you can't use = on them either. You need to use Real.== to compare reals for equality (or better: don't compare them for equality, but compare them against some delta instead).