Browse thread
Same label in different types, how do people solve this?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Mattias Waldau <mattias.waldau@a...> |
| Subject: | Same label in different types, how do people solve this? |
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}