Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Sumtypes of records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] Sumtypes of records

>>Why can't constructors of sumtypes take nameless records? (Warning stupid 
>>example follows)
>>type plop = Foo | Bar {age : int};;
>Probably because it wouldn't make much sense.  Either the only way you 
>could access age in the above is by matching Bar { age = x }, which is not 
>very useful (you might as well have Bar of int, or a tuple for multiple 
>fields),

I disagree, it would be useful, it's far more self-documenting than a tuple 
(which usually need a record-like comment right next to their declaration 
to tell what's what), and you could match the record like

Bar x -> x.age

and it wouldn't need a type name.  I've wanted this feature myself a number 
of times.

>or the record type needs to have a name so that x in the pattern Bar x has 
>some printable type.

It has type { age : int; }, just like int * int has type int * int and 
doesn't need a name.  Does the record need a name for some other reason?

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners