I’ve elected to take a course in functional programming that uses SML (Moscow ML). So far, we’ve mostly been using the interactive top level, but now I need to write an assignment in an .sml file for submission.
The problem is, whenever I write a val statement, and load my file into the interpreter, it baulks. For instance, this is my file:
fun soundex name =
val list = String.explode name;
val firstCharacter = List.nth (list, 0);
val listWithoutFirst = List.drop (list, 1);
Loading that into mosml using use “soundex.sml” produces the following error:
[opening file "soundex.sml"]
File "soundex.sml", line 2, characters 1-4:
! val list = String.explode name;
! ^^^
! Syntax error.
[closing file "soundex.sml"]
What am I doing wrong? Using the same val statements in the top level (without the function surrounding them) works fine.
Thanks.