Re: MLton-user Digest, Vol 55, Issue 1
John Reppy <[email protected]>
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <[email protected]> |
Your signature S is too polymorphic for the function eq. Also, you need equality type
variables in its specification. So the following should work:
signature S =
sig
eqtype 'a t
val eq : ''a t * ''a t -> bool
end
Note that there is no way in an SML signature to say that 'a t is an equality type for
_any_ 'a. This property only holds for the special type constructors 'a ref (discussed in
the SML definition) and 'a array (part of the Basis definition).
- John
On Sep 1, 2013, at 7:27 AM, [email protected] wrote:
> Date: Sun, 01 Sep 2013 13:27:15 +0100
> From: Phil Clayton <[email protected]>
> Subject: [MLton-user] A datatype that is, and is not, an equality
> type?
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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
------------------------------------------------------------------------------
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