[MLton-user] bug report: vector equality
Sam Lindley
Sam.Lindley@ed.ac.uk
Thu, 26 Feb 2004 23:40:06 -0000
The latest experimental release of mlton (20040221), and the previous one
from the beginning of January both fall over on the following code:
val _ =
if (Int32Vector.fromList [1])=(Int32Vector.fromList [2]) then
TextIO.print "oops"
else
TextIO.print "not equal"
$ mlton test.sml
Error: test.sml 2.32: function applied to incorrect argument
expects: [<equality>] * [<equality>]
but got: [<non-equality>] * [<non-equality>]
in: = (Int32Vector.fromList [1], Int32Vector.fromList [2])
compilation aborted: elaborate reported errors
It compiles correctly under the release version.
For some reason mlton is failing to infer that vectors of equality type are
themselves equality types. I had a brief look at the mlton source. As far as
I could tell it looks like it should do the right thing, although its
slightly hard to follow with all the signatures being merged together, uses
of use, where clauses, sharing constraints etc.
Equality on CharVectors works fine, but then they use strings as the
underlying representation type, so that's not terribly surprising.
There's an easy workaround, which I successfully used - simply map vectors
back to lists, and lists of equality type are equality comparable. I was a
bit surprised to discover that although the vector interface has a fromList
function there is no toList, but it's easy to do using foldr:
fun toList v = Int32Vector.foldr (fn (x, xs) => x::xs) nil v
In case its relevant (I very much doubt it), the release version was running
under Linux, but the experimental versions were running under cygwin.
Sam Lindley