Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* RE: [Caml-list] Polymorphism and the "for" loop
@ 2004-10-22 14:07 Harrison, John R
  2004-10-22 14:45 ` John Carr
  2004-10-22 14:47 ` Andreas Rossberg
  0 siblings, 2 replies; 25+ messages in thread
From: Harrison, John R @ 2004-10-22 14:07 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: [Caml-list] Polymorphism and the "for" loop
@ 2004-10-22 16:00 Harrison, John R
  0 siblings, 0 replies; 25+ messages in thread
From: Harrison, John R @ 2004-10-22 16:00 UTC (permalink / raw)
  To: caml-list

|
|    let rec x = Constr x
|

I stand corrected; I'd forgotten about the cyclic
structures in OCaml. It's one of those features,
like mutable strings, that my mind tries its best
to blot out and replace by a more acceptable
reality.

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


^ permalink raw reply	[flat|nested] 25+ messages in thread
* [Caml-list] Polymorphism and the "for" loop
@ 2004-10-21 18:50 Jon Harrop
  2004-10-21 19:11 ` David Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Jon Harrop @ 2004-10-21 18:50 UTC (permalink / raw)
  To: caml-list


Considering the following code objects to the expression in the "for" loop not 
having the type "unit":

# for i=0 to 3 do 1 done;;
Warning: this expression should have type unit.
- : unit = ()

why is "g" in the following code inferred to have the polymorphic type (unit 
-> 'a) rather than (unit -> unit)?

# let f g = for i=0 to 3 do g () done;;
val f : (unit -> 'a) -> unit = <fun>

Cheers,
Jon.

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


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2004-10-23 20:58 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-22 14:07 [Caml-list] Polymorphism and the "for" loop Harrison, John R
2004-10-22 14:45 ` John Carr
2004-10-23 20:58   ` Christophe Raffalli
2004-10-22 14:47 ` Andreas Rossberg
  -- strict thread matches above, loose matches on Subject: below --
2004-10-22 16:00 Harrison, John R
2004-10-21 18:50 Jon Harrop
2004-10-21 19:11 ` David Brown
2004-10-22  1:19   ` skaller
2004-10-22  2:22     ` Robert M. Solovay
2004-10-22  6:19       ` skaller
2004-10-22  7:38         ` Jon Harrop
2004-10-22  8:06           ` David Brown
2004-10-22  9:39             ` Andreas Rossberg
2004-10-22  8:13           ` William Lovas
2004-10-22  8:17             ` Jon Harrop
2004-10-22 14:02           ` skaller
2004-10-22 14:31             ` David Brown
2004-10-22 17:06         ` Brian Hurt
2004-10-22  4:17     ` William Lovas
2004-10-22  6:42       ` skaller
2004-10-21 19:12 ` Ville-Pertti Keinonen
2004-10-21 19:20   ` Jon Harrop
2004-10-21 19:42     ` Ville-Pertti Keinonen
2004-10-23 11:41 ` Richard Jones
2004-10-23 12:06   ` Matti Jokinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox