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: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] Sumtypes of records
Marcin 'Qrczak' Kowalczyk wrote:


>>type bar_anonymous_record_type_name_123 = { age : int; }
>>type foo = Bar bar_anonymous_record_type_name_123
>>
> 
> Ah, I see. Like in Turbo Pascal (I don't know about Pascal in theory) where it 
> applies to arrays and pointers too. And like structs and unions in C and C++.
> 
> I don't like it because it's confusing. The syntax suggests that record types 
> are built on the fly like tuples (like in SML) but the semantics is that they 
> are explicitly defined somewhere like algebraic types. And this would be the 
> only such case.
> 
> When you would write:
>    type foo = Foo of {x : int}
>    type bar = Bar of {x : int}
> then this is a type error:
>    let f (Foo y) = Bar y
 
There is no reason for it. The compiler

already does sophisticated signature matching.
There's no reason it can't identify all anonymous
record types with the same structure the
same way it does for tuples (and polymorphic variants).


So this *could* be consistently supported if it

was deemed useful, but I would have to warn
that anonymous types invariable lead to
difficult to understand error messages
(I use polymorphic variants extensively
and regularly get 200 line error messages).

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


-------------------
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