[MLton] confusing error message from MLton

Matthew Fluet fluet@cs.cornell.edu
Mon, 21 Jun 2004 14:52:52 -0400 (EDT)


> The error is
>     14.29: syntax error: inserting VAL
> which  certainly  confused  me.  I would have expected first to get the error
> about fiba referring to fibb (because the third `fun' should be `and').

MLton does _all_ lexing and parsing before any elaboration.  So, you won't
see any unbound identifiers or type-checking errors if there are any
syntactic errors in the program.

> Then
> I  would  expect it would have either complained about `def' being unbound or
> else about no `fun' before `def'.

Presumably, the attempt to insert a VAL arises from the use of =.
But, I don't know why the grammer isn't parsing the code with = as an
infix.  It seems like the following would be a valid parse:

fun fibb x =
       if x <= 1
          then x
          else fiba (x - 1) + (( fiba (x - 2)

def doOne arg )) = ((
       case Int.fromString arg of
         SOME arg' =>
            (print (arg ^ " => ");
             print (Int.toString (fib arg') ^ "\n"))
       | _ =>
            print ("\"" ^ String.toString arg ^ "\" is not an integer\n") ))

That is, parse the equals as infix, applied to fiba applied to 4 arguments
and to the case expression.