Browse thread
[Caml-list] Fwd: Polymorphic optional label argument, with default
[
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: | nadji <nadji@n...> |
| Subject: | Re: [Caml-list] Fwd: Polymorphic optional label argument, with default |
Le Sunday 11 April 2004 15:16, Jacques Garrigue a écrit :
> Basically, what you are asking for is a new type of constraint, which
> is only to be applied when the optional argument is omitted (and as
> result the default is selected).
> This is not possible in the current type system, and while there are
> some uses for that, it would be hard to justify making types more
> complex in the general case, just to handle this specific problem.
I would like to point out that a machinery to handle this problem
is guarded recursive datatypes proposed by Xi. It is a framework
that solves a bunch of other problems and is compatible with ml type
system (there is currently at Inria a student working on an Ocaml integration
of this type system).
Combining it with your labeled parameters leads to a well typed code
analogous to your phantom-type based solution. Some even view
Xi's GRDT as a way to avoid your Obj.magic when matching against
a phantom type.
For those interested, the pseudo code would be something like :
guarded 'a opt = Omit with 'a = int | Arg of 'a->unit
let plot : ?(labels:'a opt) -> 'a graph -> unit =
fun ?(labels=Omit) g ->
let printing_labels : 'a -> unit =
match labels with
Omit -> print_int
| Arg x -> x
in
... printing_labels node_label ...
Nadji
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners