caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] const equivalent for mutable types?
@ 2004-07-31  8:56 Christopher A. Gorski
  2004-07-31  9:24 ` Jean-Marie Gaillourdert
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Christopher A. Gorski @ 2004-07-31  8:56 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2004-08-27  9:03 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-31  8:56 [Caml-list] const equivalent for mutable types? Christopher A. Gorski
2004-07-31  9:24 ` Jean-Marie Gaillourdert
2004-07-31 10:24   ` Jean-Marie Gaillourdert
2004-07-31 10:50   ` Markus Mottl
2004-07-31 14:31     ` Brian Hurt
2004-07-31 15:51       ` Markus Mottl
2004-07-31 17:05       ` skaller
2004-07-31 10:34 ` Markus Mottl
2004-07-31 13:44   ` Jon Harrop
2004-07-31 16:31     ` [Caml-list] Phantom types Markus Mottl
2004-08-23  9:49       ` Jon Harrop
2004-08-23 12:25         ` [Caml-list] Why does ocaml use custom buffering? Daan Leijen
2004-08-23 15:16         ` [Caml-list] Phantom types Jon Harrop
2004-08-27  9:03           ` Jacques GARRIGUE
2004-08-25 21:03         ` brogoff
2004-07-31 16:35     ` [Caml-list] const equivalent for mutable types? skaller
2004-07-31 17:23       ` [Caml-list] Functional arrays Jon Harrop
2004-07-31 18:45         ` skaller
2004-08-02  5:07           ` brogoff
2004-08-02  7:45         ` Diego Olivier Fernandez Pons
2004-08-05 16:42           ` Daniel Ortmann
2004-08-05 17:02             ` Diego Olivier Fernandez Pons
2004-08-05 17:16             ` Diego Olivier Fernandez Pons
2004-07-31 17:45   ` [Caml-list] const equivalent for mutable types? Chris Gorski
2004-07-31 14:11 ` Brian Hurt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).