Skip to content

Instantly share code, notes, and snippets.

@msullivan
Last active October 10, 2015 20:17
Show Gist options
  • Save msullivan/3744805 to your computer and use it in GitHub Desktop.
Save msullivan/3744805 to your computer and use it in GitHub Desktop.
sml array indexing fail
(* Running `fail ()` at the repl will cause it to say:
unexpected exception (bug?) in SML/NJ: Representation [Representation] *)
fun fail () =
let fun idx a i =
case (Array.sub (a, i))
of NONE => raise Fail "owt"
| SOME x => x
val a = Array.array (1, SOME (42, 1337))
in idx a 0 end
(* Running `thing (fail ())` will print some bogus numbers.
* If I had thing *call* fail, then sml/nj crashed while compiling the file?? *)
fun thing x =
let val (i, j) = x
in print (Int.toString i ^ " " ^ Int.toString j ^ "\n") end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment