Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] const equivalent for mutable types?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] const equivalent for mutable types?
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