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 RAA16754; Sat, 31 Jul 2004 17:51:39 +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 RAA08562 for ; Sat, 31 Jul 2004 17:51:38 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6VFpbEV025370 for ; Sat, 31 Jul 2004 17:51:37 +0200 Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6VFpaDu016004; Sat, 31 Jul 2004 17:51:36 +0200 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) id i6VFpZ2j016003; Sat, 31 Jul 2004 17:51:35 +0200 Date: Sat, 31 Jul 2004 17:51:35 +0200 From: Markus Mottl To: Brian Hurt Cc: Jean-Marie Gaillourdert , caml-list@inria.fr Subject: Re: [Caml-list] const equivalent for mutable types? Message-ID: <20040731155135.GA15775@fichte.ai.univie.ac.at> Mail-Followup-To: Brian Hurt , Jean-Marie Gaillourdert , caml-list@inria.fr References: <20040731105002.GB11964@fichte.ai.univie.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 410BC009.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 const:01 violate:01 bug:01 non-mutable:01 const:01 ignoring:01 pointers:01 newbies:01 pound:99 committing:99 ocaml:01 mutable:01 anyways:02 mottl:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 31 Jul 2004, Brian Hurt wrote: > The problem is that if the called function *can* modify the argument, > there is an extra, uncheckable, dependency between the caller and called > functions. The depedency can work in both ways- with the caller depending > on the called function changing the argument in some known way, or with > the caller depending upon the called function not changing the argument. > If you violate these constraints, you can easily wind up with a bug. Sure. That's also why I think that using non-mutable datastructures should always be preferred. > Another thing to note: const in C/C++ isn't. I can always type cast > around the const and modify the memory anyways. Even ignoring wild > pointers. Well, you can also always use Obj.magic in OCaml (newbies beware: DON'T!)... ;-) > Worrying about how long it takes to allocate a new structure is being > pennywise and pound foolish- and committing premature optimization. I wasn't referring to optimization, this is a different topic. But there may also be semantic issues. E.g. you may not want to lose the possibility of using physical identity (==) on structures. Regards, Markus -- Markus Mottl http://www.oefai.at/~markus markus@oefai.at ------------------- 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