Question
I have this snippet of the code in ML:
local
fun unfolder( [] , n ) = []
| unfolder( l::ls, n ) = (n, l) :: unfolder( ls, n )
in
fun flat list = unfolder(list, 1)
end;
it gives me an error:
unexpected exception (bug?) in SML/NJ: EA [EA]
raised at: ../../MLRISC/x86/mltree/x86.sml:417.32-417.34
../compiler/Basics/stats/stats.sml:198.40
../compiler/Basics/stats/stats.sml:198.40
../compiler/Basics/stats/stats.sml:198.40
../compiler/TopLevel/interact/evalloop.sml:44.55
but when I change its (n, l) to (n, l:int)
it works, and when to (n, l:'a)
, can somebody please explain why polymorphic type doesn't work, thanks in advance
Solution
It is an internal bug in SML/NJ. The program works flawlessly if compiled with MLton, adding:
val _ =
let val l = flat [1,2,3]
fun printer (a,b) = Int.toString(a) ^ ", " ^ Int.toString(b)
in
print (printer (hd l) ^ "\n")
end
Report it. Your example seem digestible in size - and probably has to do with polymorphism representation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow