caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Same label in different types, how do people solve this?
@ 2000-12-06 21:22 Mattias Waldau
  2000-12-07 16:49 ` John Max Skaller
                   ` (5 more replies)
  0 siblings, 6 replies; 31+ messages in thread
From: Mattias Waldau @ 2000-12-06 21:22 UTC (permalink / raw)
  To: Caml-List

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?

Also, I am a bit curious why it doesn't help to type explicitely, i.e. to
write
let x:point_3d={x=10.;y=20.;z=30.} ???

/mattias


type point_3d = {
    x:float;
    y:float;
    z:float;
  }

type point_2d = {
    x:float;
    y:float;
  }

# {x=10.;y=20.;z=30.};;
Characters 0-19:
The record field label z belongs to the type point_3d
but is here mixed with labels of type point_2d
# {x=10.;y=20.};;
- : point_2d = {x=10.000000; y=20.000000}




^ permalink raw reply	[flat|nested] 31+ messages in thread
* RE: ROverloading
@ 2000-12-18 15:27 Dave Berry
  2000-12-19  6:45 ` ROverloading John Max Skaller
  0 siblings, 1 reply; 31+ messages in thread
From: Dave Berry @ 2000-12-18 15:27 UTC (permalink / raw)
  To: John Max Skaller, Mattias Waldau; +Cc: caml-list

John Max Skaller wrote:

> 	Unfortunately, overloading isn't quite so simple when 
> you've also got type inference:

That depends on how general you try to be.  I'd be quite happy with a system
that allowed multiple definitions of a name, but forced applications to be
monomorphic.  In your example, the definition of f would require a
disambiguating type annotation (or assume a default):

>	let f a b = a + b in
>	let x = f 1.0 2.0 in
>	let y = f 1 2 in 

would become

	let f a b = a + b : int in ...

Theoretically inelegant, but pragmatically sufficient.  As indeed you seem
to be doing in Felix.

I'd use the module system to introduce and control overloading, rather than
trying to extend the core language.  It seems a simpler route.

Dave. 



^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2000-12-19 16:29 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-06 21:22 Same label in different types, how do people solve this? Mattias Waldau
2000-12-07 16:49 ` John Max Skaller
2000-12-07 18:34 ` Maxence Guesdon
2000-12-07 23:02 ` Gerd Stolpmann
2000-12-08  1:22 ` Jacques Garrigue
2000-12-08  9:31   ` Sven LUTHER
2000-12-08  9:36     ` Pierre Weis
2000-12-08  9:48       ` Sven LUTHER
2000-12-08 18:41       ` John Max Skaller
2000-12-08  9:40     ` Nicolas barnier
2000-12-08 16:36 ` Brian Rogoff
2000-12-11 17:19   ` Pierre Weis
2000-12-10 12:49 ` Mattias Waldau
2000-12-11 18:23   ` Chris Hecker
2000-12-11 19:17     ` Pierre Weis
2000-12-12 10:02       ` Sven LUTHER
2000-12-12  3:25     ` Chet Murthy
2000-12-12 17:43       ` John Max Skaller
2000-12-12 19:24         ` Functions must be explicitly typed, (was Same label in different types, how do people solve this?) Mattias Waldau
2000-12-13  0:51           ` John Max Skaller
2000-12-15 10:13             ` Andreas Rossberg
2000-12-15 12:50             ` Frank Atanassow
2000-12-14 18:42           ` Stefan Monnier
2000-12-15 12:47             ` Pierre Weis
2000-12-15 13:39               ` Mattias Waldau
2000-12-15 23:37                 ` Brian Rogoff
2000-12-16 14:10                 ` ROverloading John Max Skaller
2000-12-15 21:51         ` Same label in different types, how do people solve this? Bruce Hoult
2000-12-12 17:19   ` John Max Skaller
2000-12-18 15:27 ROverloading Dave Berry
2000-12-19  6:45 ` ROverloading John Max Skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).