Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Void type?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-28 (18:57)
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.

Arnaud Spiwack