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 label in different types, how do people solve this?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-12-08 (09:07)
From: Maxence Guesdon <max@s...>
Subject: Re: Same label in different types, how do people solve this?
Mattias Waldau a écrit :
> In Ocaml, you cannot have the same label in different types, see the example
> below where
> point_2d hides point_3d.
> How do people normally code around this restriction? One solution is using
> objects, but what other solutions are there? Can 'Polymorphic variants'
> solve this?

In your example, and without objects, I would have chosen explicit names
for labels, i.e. :

type point_3d = {
type point_2d = {

It sure is kind of a pain to write, but it is much more easy to
understand when you read it. With
explicit labels, you "see" the type of toto in toto.p3d_x. I think not
allowing to have the same label
in different types is a great way to force developers to write cleaner
code ;-)

Maxence Guesdon