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
[Caml-list] Polymorphism and the "for" loop
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-10-22 (16:57)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Polymorphism and the "for" loop
On 22 Oct 2004, skaller wrote:

> On Fri, 2004-10-22 at 12:22, Robert M. Solovay wrote:
> > How does one define a function f of type int -> void? I looked in the
> > OCaml manual and couldn't find any reference to "void". {It is, of course,
> > a familiar concept in C.}
> That's right. Ocaml has no void type. I consider that a bug.

unit is Ocaml's void.  There are some subtle differences, but generally 
anything you use void for in C, you use unit for in Ocaml.

As a side note, the correct return type for functions that don't return is 
'a.  This allows code like:

let do_something = function
	| h :: _ -> h
	| [] -> invalid_arg "do_something failed!"

Note that the invalid_arg function has a type string -> 'a.  

"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: