Version française
Home     About     Download     Resources     Contact us    
Browse thread
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: Anton Moscal <msk@p...>
Subject: Re: anonymous record types in variants
On Wed, 17 Feb 1999, Xavier Leroy wrote:

> It could be implemented this way.  However, if you declare the
> datatype as
> 
>         type foo = A of {lbl1 : int; lbl2 : int}
> 
> you would be forced to pattern-match it as follows
> 
>         match x with A{lbl1 = x; lbl2 = y} -> ...
> 
> but you can't get access to the record itself and use the dot notation
> on it, as in
> 
>         match x with A r -> ... r.x ... r.y ...

But why? Natural semantic for anonymous types is the following: each
anonymous record or algebraic types declaration introduces new type
declaration in the current scope with some temporary type name. I.e.

	type ('a, 'b) foo = A of 'a * {l : 'b; l2: int}

is a shortcut for:

	type ('a, 'b) temp_name = {l1 : 'b; l2: int}
	and  ('a, 'b) foo = A of 'a * ('a, 'b) temp_name

Regards, 
Anton Moscal