I am reading Programming with Standard ML by Colin Myers, Chris Clack, and Ellen Poon. In § 2.4.1 Restricted polymorphic functions:
Unlike the operators
=
and<>
, the other comparison operators (>
,<
etc.) are overloaded; they are not restricted polymorphic and therefore the following definition fails:- fun wrong_ordered (x, y, z) = (x < y) andalso (y < z); Error: overloaded variable "<" cannot be resolved
This failure occurs because SML does not know the types of
x
,y
andz
.
When I entered that definition into SML/NJ 110.99.2 and Poly/ML 5.9, I did not get any error message. The definition succeeds:
- fun wrong_ordered (x, y, z) = (x < y) andalso (y < z);
val wrong_ordered = fn : int * int * int -> bool
Why did I not get the error that the authors said I would be getting?
The book predates SML'97. With that language version, type resolution for overloaded operators was refined. In particular, overloaded types now default to int
when they cannot be resolved by context.