Consider such code:
fun equals(a : 'a,b : 'a) =
a = b;
My code is bigger, but this is the problem. SML reports “Error: operator and operand don’t agree”.
I am complete beginner with SML, and I have not clue why it complains. Is this something similar to C# problem, that you cannot really compare two values of any type, but you have to use default equality comparer for the type? Should I add some constraint on 'a (I hope I wrote it correctly as generic type)?
Instead of
'a, use''a.A type with two quotation marks in front of it instead of one is an equality type, which means that the
=operator works on it. That also means that you can’t call your function on things that are not equality types, though.Also, you don’t actually have to write the types. If you just do:
SML will infer the type.