Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Functional > Combining mutab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 2817 of 2841
Post > Topic >>

Combining mutable objects with const references

by anonposting@[EMAIL PROTECTED] Apr 22, 2008 at 07:32 AM

Hello

I would like to suggest a simple feature for functional languages.
First I will introduce a problem. In a functional language, typically
references cannot be mutated. For example, if I have an identifier n
bound to the value 3, it will not later be bound to the value 4 within
the same scope. This is a good thing. Similary if an identifier p is
bound to a point object, which is made up of an x-coordinate and y-
coordinate, then p cannot later refer to an object which is made up of
a different x and/or y. This means that to change a single component
of an object requires making a new object. For example, moveLeft(p)
must return a new point object. This can be wasteful in especially in
the case of large nested objects, which is a bad thing.

As far as I am aware, the only current practical solution to this
problem, is to allow objects to be muted and to therefore lose the
const property of identifiers, that is, always refering to the same
value. But it the solution used by OCaml and F#. (Right?) However, it
does not have to be this way. Imagine we could use the following
syntax (refering to our point p from earlier):
(p where x is 5)
This can be an expression which mutates the underlying storage of p to
return a conceptually-new object which is the same as p in every way
except for its x-value. All that is left is to ensure that the
reference p is not used after the underlying storage has been mutated.
I don't believe there would be any trouble in making the compiler
enforce this. In essence, it would have to keep track of which
parameters a function mutates and not allow an argument which will  be
mutated to be used elsewhere in the same expression.

This would allow object-based programming in a functional language
without losing the constant-ness of reference feature. What are your
thoughts on this? Is it a good idea? Has it already been implemented?
Do you think there is a problem in the first place?

Over




 16 Posts in Topic:
Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-22 07:32:52 
Re: Combining mutable objects with const references
=?ISO-8859-1?Q?Pertti_Kel  2008-04-22 23:23:43 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-23 06:12:53 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-23 14:05:57 
Re: Combining mutable objects with const references
torbenm@[EMAIL PROTECTED]  2008-04-24 09:35:17 
Re: Combining mutable objects with const references
=?ISO-8859-1?Q?Matti_Nyk=  2008-04-24 09:46:58 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-24 10:36:38 
Re: Combining mutable objects with const references
Paul Rubin <http://phr  2008-04-24 11:39:31 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-24 14:13:19 
Re: Combining mutable objects with const references
Paul Rubin <http://phr  2008-04-24 19:04:30 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-25 04:13:13 
Re: Combining mutable objects with const references
rossberg@[EMAIL PROTECTED  2008-04-25 06:57:19 
Re: Combining mutable objects with const references
Paul Rubin <http://phr  2008-04-25 09:42:29 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-26 05:38:40 
Re: Combining mutable objects with const references
anonposting@[EMAIL PROTEC  2008-04-26 06:07:26 
Re: Combining mutable objects with const references
rossberg@[EMAIL PROTECTED  2008-04-26 10:04:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 21:28:23 CDT 2008.