Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-05-17 (01:36)
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 

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?


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: