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: | 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 some_value else invalid_arg "some_test failed!" and have it work for all possible return types of some_value. Brian