Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 :

{p3d.x=10.;p3d.y=20.;p3d.z=30.}

and 

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

Would this be difficult to do ?

Friendly,

Sven Luther