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 BAA05852; Fri, 8 Jun 2001 01:50:35 +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 BAA05342 for ; Fri, 8 Jun 2001 01:50:33 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f57NoW901928 for ; Fri, 8 Jun 2001 01:50:32 +0200 (MET DST) Received: from localhost (isdnppp2.kurims.kyoto-u.ac.jp [130.54.16.103]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id IAA23479; Fri, 8 Jun 2001 08:50:11 +0900 (JST) To: tom7ca@yahoo.com Cc: williamc@paneris.org, caml-list@inria.fr Subject: [Caml-list] let mutable (was OCaml Speed for Block Convolutions) In-Reply-To: <20010607182007.33358.qmail@web11902.mail.yahoo.com> References: <15134.30731.137189.386800@beertje.william.bogus> <20010607182007.33358.qmail@web11902.mail.yahoo.com> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010608084947C.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 08 Jun 2001 08:49:47 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk About the introduction of a let mutable construct, Tom _ wrote > In any case, whether or not the compiler in the > current implementation can or cannot do good type > inference and may or may not be forced to box > a floating point number, the two constructs mean > something different to the programmer, and they > behave differently. In particular "mutable x" > can never be passed around as a reference, while > "x = ref ..." can. If not anything else, that > prevents the programmer from inadvertently inhibiting > a compiler optimization by passing around a reference. Not exactly, the compiler may still need to build a reference. let mutable x = 0 in List.iter (fun y -> x <- x+y) l; x Since x has to be modified in a function called by iter, it must be wrapped into an actual reference cell. As the compiler already does a good job at unboxing only locally used references, let mutable would only be some syntactic sugar (with exactly the same typing as a reference). > Besides, the syntax is probably quite a bit more > natural to imperative programmers anyway. This is actually the only argument for let mutable. I would also like such a construct, but I don't know whether its worth it. The real question is whether let mutable should be allowed at toplevel, with problems for both answers. Cheers, Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr