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:24)
From: Sven LUTHER <luther@d...>
Subject: Re: Same label in different types, how do people solve this?
On Fri, Dec 08, 2000 at 10:22:29AM +0900, Jacques Garrigue wrote:
> From: "Mattias Waldau" <mattias.waldau@abc.se>
> > 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?
> There are various ways. The most common is to differentiate label
> names (i.e. use x_3d and x_2d instead of x). Another more subtle one
> is to put the definitions in deifferent modules (Point2d and Point3d)
> so that you can specify exactly which label you want (Point2d.x or
> Point3d.x).
> The last solution might be nicer if we had a
>     let open Module in
> construct (would require 10 lines in the compiler)

Is this not already possible ? i read about something similar in the docs
somewhere ...

Another idea would be to add some construct to use something like :

type p3d = { x:float;y:float;z:float }
type p2d = { x:float;y:float }

and then be able to do :



{p2d.x=0; p2d.y=5}

Would this be difficult to do ?


Sven Luther