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]>
That's very useful.  Now you say it, it seems obvious!  I was lost in a 
cyclic data structure somewhere...  Thanks Andreas and Adam for your 
quick replies.

01/09/13 15:23, Andreas Rossberg wrote:
> On Sep 1, 2013, at 14:27 , Phil Clayton <[email protected]> wrote:
>> 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.
>
> Yes, but note that for parameterized types, being an equality types means that you can use equality if (and only if) all its parameters are instantiated with equality types as well.
>
> Consequently, your signature would at least need to say (note the equality type variables for eq):
>
>>    signature S =
>>      sig
>>        eqtype 'a t
>>        val eq : ''a t * ''b t -> bool
>>      end
>
> That's the source of the specific type error you see. However, as Adam pointed out, even if you fixe that, the more serious problem with your code is that your signature match also tries to instantiate the same type variable with two different types, ''a t and ''b t. Again, this does not work, because type equivalence for parameterized datatypes likewise requires all arguments to be equal.
>
> The issue in both these cases is that datatypes are nominal, i.e. the type constructors are treated as abstract. Consequently, their definition does not matter, so unused parameters do not provide any more freedom than others. The rules are the same as they would be for
>
>    datatype 'a t = A of 'a
>
> /Andreas
>
>
>

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.