A datatype that is, and is not, an equality type?
Phil Clayton <[email protected]>
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <[email protected]> |
This is more of a general SML question - apologies for hijacking the
MLton list.
I'm confused about whether a particular datatype can be used as an
equality type. The following code was accepted by MLton, Poly/ML and
SML/NJ:
signature S =
sig
eqtype 'a t
end
structure S :> S =
struct
datatype 'a t = A of int
end
which suggests that 'a t is an equality type. However, none of them accept
signature S =
sig
eqtype 'a t
val eq : 'a t * 'b t -> bool
end
structure S :> S =
struct
datatype 'a t = A of int
fun eq (a, b) = a = b
end
on the grounds that 'a t is _not_ an equality type! (HaMLet behaves
similarly but does not give such a specific error message.) I would be
grateful if someone could explain what is going on here.
In the end, I worked around the problem by defining
fun eq (A a, A b) = a = b
instead. In my actual code, the example was not so pathological: I had
something more like
datatype 'a t = A of 'a ref
so the type parameter was actually used.
Phil
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk