English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Same name fields
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-11-21 (15:55)
From: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] Same name fields
Mykola Stryebkov wrote:
> I'm trying to declare to record types with fields having the same name
> but different types.

This is not possible with record types (at the same module scope) - when you
declare the second type you obscure the previous type.


> If I declare type ta second - everything works fine.
> Is it a bug?

No :o)

> If not, what is an appropriate workaround here?

Either put types ta and tb in separate modules (then you can use qualified
field names) or use different field names. The Unix module in the Standard
Library is a good example of how to do all this in practice - the record
types there all have standard prefixes on the field names.

The other alternative is to use objects but this is heavier in terms of
memory and field access and the type errors messages are more confusing than
with records (but neither of these reasons are necessarily bars to using


PS Not that it I think it generally offends people on this list, but this
question would have been more appropriate for the Beginners' List -