Question

The code below works when typed in the REPL:

type seat = seat_type * int
val my_seat = (Window, 13)

fun aow seat =
    case seat of
    (Window,_) => "Window"
      | (Aisle,_) => "Aisle"

fun is_window (x,_) = x = Window

aow my_seat
is_window my_seat

But if saved in a file and compiled, the expressions aow my_seat and is_window my_seat fail with the following error during compilation:

test1.sml:12.23-16.18 Error: operator is not a function [tycon mismatch]
  operator: seat_type
  in expression:
    Window aow

uncaught exception Error
  raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
             ../compiler/TopLevel/interact/evalloop.sml:44.55
             ../compiler/TopLevel/interact/evalloop.sml:296.17-296.20

If I comment them out, the file compiles and when I type both expressions in the REPL, they work. What may cause this error? And also, if it is relevant, comments about my datatype and type definitions is more than welcome, as I don't see myself fit on this subject.

Was it helpful?

Solution

Adding a val statement before both expressions like:

val x = aow my_seat
val y = is_window my_seat

lets the file compile. Seeing that, I also tried to replace fun before aow and is_window functions. However this results in the following very logical error:

Error: syntax error: replacing  VAL with  FUN

Apparently, SML does not allow footloose expressions during compilation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top