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 QAA12502; Thu, 8 Jan 2004 16:47:11 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA12545 for ; Thu, 8 Jan 2004 16:47:10 +0100 (MET) Received: from cgpsrv2.cis.mcmaster.ca (cgpsrv2.CIS.McMaster.CA [130.113.64.62]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i08Fl8526075 for ; Thu, 8 Jan 2004 16:47:09 +0100 (MET) Received: from [65.48.130.10] (account ) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro WebUser 4.0.6) with HTTP id 5897000; Thu, 08 Jan 2004 10:47:04 -0500 From: "Jacques Carette" Subject: Re: [Caml-list] Reason why 'for' doesn't work across floats? To: Michal Moskal , caml-list@inria.fr X-Mailer: CommuniGate Pro Web Mailer v.4.0.6 Date: Thu, 08 Jan 2004 10:47:04 -0500 Message-ID: In-Reply-To: <20040108150358.GA6893@roke.freak> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format="flowed" Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; jacques:01 caml-list:01 floats:01 michal:01 moskal:01 malekith:01 pld-linux:01 2004:99 floats:01 printf:01 0.001:99 printf:01 debugging:01 jacques:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michal Moskal wrote: > On Thu, Jan 08, 2004 at 02:11:52PM +0000, Richard Jones wrote: > > Is there a particular reason why I shouldn't be allowed to step over > > floats? > > > > # for r = 0. to 9. step 1. do printf "%f" r done;; > > -- > > This expression has type float but is here used with type int > > let f a b = for x = a to b do () done > > What type would f have (int -> int -> int or float -> float -> float)? > One would need "for.", which doesn't seem appealing. Another reason is that for r = 0. to 9. step 0.001 do printf "%f" r done;; will not necessary have the expected number of iterations, since 9. will not be 'hit' exactly (numerical round-off guarantees that). For some loops, the number of times around would change depending on whether all the numbers involved have exact base 2 representations or not. Very ugly. After suffering through painful debugging sesions on programs in languages that allow the above type of loops, I am quite glad that Ocaml does not allow this, even if in this case it is because of typing rather than sound numerical analysis... Jacques ------------------- 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