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 (13:26)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Re: Void type?

On Sat, 28 Jul 2007, Basile STARYNKEVITCH wrote:

> 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.

The proper type for these functions would be f : int -> 'a.  Take a look 
at invalid_arg and failwith as examples.  The advantage of having them 
return an unbound 'a is that then unifies with any other given type, 
allowing you to write code like:

 	if (some_test) then
 		invalid_arg "some_test failed!"

and have it work for all possible return types of some_value.