Browse thread
RE: [Caml-list] Polymorphism and the "for" loop
- Harrison, John R
[
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: | 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 convey | a similar semantic notion using polymorphism. Consider the function raise, | which has type "exn -> 'a" -- in other words, given an exception, it | produces an arbitrary value of any type. Since such a thing is impossible | (using the type-safe core language), we must conclude that raise does not | 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 like this: # 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> or # let (g:int->void) = fun x -> failwith "void function";; val g : int -> void = <fun> or # 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. John. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners