Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Polymorphism and the "for" loop
On Thu, Oct 21, 2004 at 07:50:43PM +0100, Jon Harrop wrote:
> 
> 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>

Because its only a warning, not an error.  g is allowed to return any type.
It could be argued that the loop expression must be of type unit, then this
could also be inferred by type inference.

Dave

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