From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA10503; Thu, 21 Oct 2004 21:13:09 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA10339 for ; Thu, 21 Oct 2004 21:13:08 +0200 (MET DST) Received: from will.iki.fi (will.iki.fi [217.169.64.20]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9LJD7MU020492 for ; Thu, 21 Oct 2004 21:13:08 +0200 Received: from [192.168.1.101] (KMCCXI.dsl.saunalahti.fi [195.197.18.211]) by will.iki.fi (Postfix) with ESMTP id 67205C3; Thu, 21 Oct 2004 22:13:03 +0300 (EEST) Message-ID: <41780A38.4030505@exomi.com> Date: Thu, 21 Oct 2004 22:12:56 +0300 From: Ville-Pertti Keinonen User-Agent: Mozilla Thunderbird 0.8 (X11/20041016) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jon Harrop Cc: caml-list Subject: Re: [Caml-list] Polymorphism and the "for" loop References: <200410211950.43396.jon@jdh30.plus.com> In-Reply-To: <200410211950.43396.jon@jdh30.plus.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41780A43.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 inferred:01 val:01 infer:01 ocaml:01 polymorphic:01 objects:02 unit:03 unit:03 wrote:03 explicitly:03 let:04 probably:05 polymorphism:06 loop:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = > > Consider the fact that it's a warning as opposed to an error. An expression with a result that isn't used (fairly rare in OCaml) is a special case; any type is permitted, but an explicitly non-unit type generates a warning, since it's probably an error. If the type system were more advanced, your second example would infer a type of "unit -> 'a ". If your second example produced a type of unit -> unit for g, I think your first example should fail with an error (rather than be accepted with a warning). ------------------- 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