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 KAA02833; Sat, 31 Jul 2004 10:56:21 +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 KAA02566 for ; Sat, 31 Jul 2004 10:56:20 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from seminole.vervehosting.com (221059.ds.nac.net [66.246.72.191]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6V8uIEV021535 for ; Sat, 31 Jul 2004 10:56:19 +0200 Received: from pa-bethlprk-cad2-grp1-4-109.pittpa.adelphia.net ([24.50.168.109] helo=[192.168.0.101]) by seminole.vervehosting.com with asmtp (TLSv1:AES256-SHA:256) (Exim 4.34) id 1Bqpez-0002hL-PL for caml-list@inria.fr; Sat, 31 Jul 2004 04:56:09 -0400 Message-ID: <410B5EBD.6060800@cgorski.org> Date: Sat, 31 Jul 2004 04:56:29 -0400 From: "Christopher A. Gorski" User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] const equivalent for mutable types? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner: Found to be clean X-MailScanner-From: cgorski@cgorski.org X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - seminole.vervehosting.com X-AntiAbuse: Original Domain - inria.fr X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - cgorski.org X-Miltered: at nez-perce with ID 410B5EB2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; const:01 passing:01 reproducing:01 const:01 incr:01 printf:01 printf:01 compiler:01 chris:01 ocaml:01 ocaml:01 mutable:01 mutable:01 complex:03 behavior:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk In my code I find that I'm passing a lot of mutable values to functions. Some functions merely read the values. Others modify the values. Is there a method in OCaml for reproducing behavior similar in spirit to the const declaration in C? Here is a specific case of the general problem: let t=ref 0 let change r = incr r let nochange r = Printf.printf "test:%d\n" !r The problem is that in complex programs I often get confused over what functions are modifying values and what functions are not. I feel like I should be able to do something like let result = change (const r) and have the compiler give me a type error. Is there a way to do this in OCaml? Should I change my programming style? Am I asking a naive question that's already been answered many times over in a different form? -- Chris Gorski - http://cgorski.org ------------------- 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