Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: anonymous record types in variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Don Syme <dsyme@m...>
Subject: RE: anonymous record types in variants

> >   type foo_one = {one: int}
> >   type foo_two = {two: string}
> >   type foo = One of foo_one | Two of foo_two
> > 
> > But, just out of curiosity, is there a quick explanation of 
> why it is this
> > way?
> 
> Basically, because "{one : int}" is not a type expression, and the
> argument of a constructor must be a type expression.
> 
> The reason why "{one : int}" is not a type expression but must be
> declared and bound to a type name have to do with type inference
> and the existence of principal types.  If you allow record types in
> type expressions (as in SML), some functions have no principal type,
> such as fun x -> x.l.

I think all we're thinking of is a mechanism so the user doesn't have to
write
nonsense type names such as foo_one and foo_two as in the above example.  
Within a (mutually recursive) type declaration, shouldn't it
be feasible to use tuples, records and variants freely, as long as all the
names 
of all the fields and constructors are used at only one place in the
declaration?
Of course you would always need named types for recursive type constructors.

Cheers & thanks,
Don

------------------------------------------------------------------------
At the lab:                                     At home:
Microsoft Research Cambridge                    11 John St
St George House                                 CB1 1DT
Cambridge, CB2 3NH, UK
Ph: +44 (0) 1223 744797                         Ph: +44 (0) 1223 722244
http://research.microsoft.com/users/dsyme
email: dsyme@microsoft.com
   "You've been chosen as an extra in the movie
        adaptation of the sequel to your life"  -- Pavement, Shady Lane
------------------------------------------------------------------------