Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-07-31 (15:51)
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.


Markus Mottl

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: