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 (08:13)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] Re: Void type?
Sébastien Hinderer wrote:
> Stefan Monnier :
>> Is there a void type in OCaml (i.e. a type which has no values), or a way to
>> simulate it?
> What about
> type void = { v : void };;

You can build such a value with
let rec vv = { v = vv };;

Generally speaking, the unit type whose single value is () is used in Ocaml for what C calls the void type: unit 
returning functions are procedures.

A void type would be useful for bizarre functions like f : int -> void
this would mean that f never returns normally, i.e. that it loops indefinitely, or
calls exit (to stop the entire program), or throws an exception but never returns.

AFAIK, there is no such void type in Ocaml (but some members of Gallium did publish papers mentioning void).

However, there is one thing I did not understand: why (= what for) does Stefan Monnier want a void type?

email: basile<at>starynkevitch<dot>net | mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***