Browse thread
Void type?
[
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: | Arnaud Spiwack <aspiwack@l...> |
| Subject: | Re: [Caml-list] Void type? |
> But can I pass [] to a function that expects a "void list"?
>
If you want to do this sort of things. Then you have two basic ways :
1/ using the revised syntax :
type void = []; .
which has an elimination principle let void_elim x = match x with [];
2/ using an abstract module with declarations :
type void
val void_elim : void -> 'a
This module would be the generic representation of a void type. It
can be instantiated by the concrete definitions in 1/.
Another way is to cheat :
type void = unit
type void_elim = Obj.magic
This implementation is sound since there is no way provided to build
an element of type void, thus void elim will never be executed.
Depending on what exactly you want to do you might disregard the
elimination principle. But it's inherently part of the void logic.
Regards,
Arnaud Spiwack