Re: 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]> |
01/09/13 13:42, Adam Chlipala wrote:
> On 09/01/2013 08:27 AM, Phil Clayton wrote:
>> 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!
>
> That's not what I see from SML/NJ, and not what I'd expect from my
> understanding of SML. Rather, the issue with [eq] is that equality only
> works on two operands of the _same_ type, whereas here you are trying to
> apply it on values of _different_ types ['a t] and ['b t]. This notion
> of "different" comes from SML's basic semantics of datatype declarations.
Good point. That was a mistake in the example and not actually the
issue I was intending to ask about. Sorry. I should have said that
none of them accept
signature S =
sig
eqtype 'a t
val eq : 'a t * 'a 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 (even though it is
accepted as an equality type as shown in my previous message).
> As we would expect from that explanation, the following module
> definition works fine:
>
> structure S :> S =
> struct
> datatype t' = A of int
> type 'a t = t'
> fun eq (a, b) = a = b
> end
That's a better work-around when the type parameter is not referenced in
the datatype. For the actual example, I have
datatype 'a t = A of 'a ref
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