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
RE: [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 (14:07)
From: Harrison, John R <johnh@i...>
Subject: RE: [Caml-list] Polymorphism and the "for" loop
| (Incidentally, O'Caml doesn't really need a type "void" since it can
| a similar semantic notion using polymorphism.  Consider the function
| which has type "exn -> 'a" -- in other words, given an exception, it
| produces an arbitrary value of any type.  Since such a thing is
| (using the type-safe core language), we must conclude that raise does
| return to its call site when it executes.)

That's true. In any case I assume (given that a recursive type is some
kind of least fixed point) that you can define an empty type in OCaml

  # type void = Constr of void;; 
  type void = Constr of void

So the only functions into such a type are those that never terminate
and return a value, e.g.

  # let rec f x = (f:int->void) x;;
  val f : int -> void = <fun>


  # let (g:int->void) = fun x -> failwith "void function";;
  val g : int -> void = <fun>


  # let (h:int->void) = fun x -> if x = 0 then f x else g x;;
  val h : int -> void = <fun>

Perhaps the name "void" in C is a bit poorly chosen. It's probably meant
to say that an element of the type imparts no information, rather than
imply a semantic model based on an empty type.


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