immutable

How does one use cached data in a functional language such as Erlang?

I've been reading a bit lately about functional languages. Coming from 10+ years of OO development, I'm finding it difficult to get my head around how on earth one can point the pure functional approach (i.e. the same method called with the same parameters does the same thing) at a problem where typically (in an OO program) I would need ...

Possible ways of making an Object immutable

I am looking for some efficient way for building a immutable class, just like Java's String class. ...

Is immutability useful on non parallel applications?

I like the immutability concept but sometimes I wonder, when an application isn't meant to be parallel, should one avoid making things immutable? When an application isn't multi-threaded, you aren't plagued by shared state problems, right? Or is immutability a concept like OOP that you either use all the way or not? Excluding the cases...

immutable java

immutability, any good sources on writing immutable programs in a functional way with java? shifting over to erlang - scala - clojure is not a possibility. ...

Make Object Immutable at Runtime [C#]

Is there any way (utilizing Reflection I hope) that I can make an instantiated object immutable along with all of its public properties? I have a class from someone else's codebase (no source available) that I need to utilize and I basically want an exception to be thrown if any piece of code anywhere tries to call a public setter within...

Does C#/CLR contain a mechanism for marking the return values of properties as read-only / immutable?

I've been looking around, and so far haven't managed to find a good way to do this. It's a common problem, I'm sure. Suppose I have the following: class SomeClass : IComparable { private int myVal; public int MyVal { get { return myVal; } set { myVal = value; } } public int CompareTo(object ot...

Immutable struct with collection

I'm making an immutable struct in .Net which contains a read only collection of a different immutable struct (I have full control over the entire design). I don't need a non-mutating Add method. What's the best way to do that? I could make the outer struct have a reference to a ReadOnlyCollection containing the inner struct. Are ther...

objective-c "mutating method sent to immutable object" error

Hi guys, I'm pretty new to objective-c and try to create a small app for the iphone. I'm nearly done beside this little error here. Actually, I've searched hours with google to find a proper solution but unfortunately I'm not able to find a solution which works. I'm using this tutorial here to build up an UITableView: UITableView Tutori...

Immutability and XML Serialization

I have several classes that are immutable once their initial values are set. Eric Lippert calls this write-once immutability. Implementing write-once immutability in C# usually means setting the initial values via the constructor. These values initialize readonly fields. But if you need to serialize a class like this to XML, using eith...

Map pointers to immutable objects with Hashtable in .NET

I have a Hashtable object which "names" or "map" various fields in a class with a string ref class Interrupt{ Interrupt(){ this->type = 0; this->size = 0; } int type; int size; } Interrupt^ interrupt = gcnew Interrupt(); Hashtable^ map = gcnew Hashtable(); map->Add("InterruptType", interrupt->type); map->Add("Interrup...

Efficient Immutable Map Implementation?

Hi, I'm wondering if there is an implementation of a map which is: Immutable, so that I can use it in functional programming, and effortlessly ensure transactions and concurrency. Fast. I've checked out Binary Search Trees (RB, AVL) and Tries, but none of them seemed to be as fast as Hash Tables. Is there a map implementation that supp...

immutable properties of an object in C#

I'm looking for a way to sort a list of object (of any type possible) so that whatever happens to the objects, as long as they are not destructed, the order keeps the same (so the hashCode isn't a good idea because in some classes it's changing over a time), for that reason I was thinking to use the address of the object in the memory bu...

How to modify an immutable object?

Sorry I couldn't think of a good title for this question... At application start I load objects from a database via a DB access library, lets call their class CDbObject. class CDbObject { //... virtual CState getState() const { return m_state; } protected: CState m_state; } At runtime, I receive messages which correspond t...

F# : Accessing public readonly members of structs in external assemblies

I'm getting a strange error when I use F# to read a public readonly member of a struct type defined in a C# assembly. // C#: compile to Lib.dll namespace Lib { public class MyClass { public readonly int ReadonlyFoo; } public struct MyStruct { public readonly int ReadonlyFoo; public int WriteableFoo; } } ...

Immutable arrays in .net (c#): Reasonable approach?

You know probably the following problem: You want to share a collection between two objects A and B (or similarly want to expose a collection by a property) and ... well, you realize that this is actually not a good idea since both A and B can then modify the collection and blah blah armageddon now ... But often you realize that you don...

Xaml serialization and immutable structs?

How can I do this? Tried using a TypeConverter, but the only thing I could think of was to construct the XML for the types, which doesn't quite cut it. TypeConverters in xaml serialization will escape xml and treat it like plain text. Value converters aren't much better. Now, I'm moving to ISupportInitialize and will throw if changes...

assign "it" in each iteration (groovy)

Hey, i try to trim each string item of an list in groovy list.each() { it = it.trim(); } But this only works within the closure, in the list the strings are still " foo", "bar " and " groovy ". How can i achieve that? ...

Empirical data on the effects of immutability?

In class today, my professor was discussing how to structure a class. The course primarily uses Java and I have more Java experience than the teacher (he comes from a C++ background), so I mentioned that in Java one should favor immutability. My professor asked me to justify my answer, and I gave the reasons that I've heard from the Ja...

What are the advantages of immutable objects over static methods?

interface IDependency { string Baz { get; set; } } class Foo { IDependency dependency; public Foo(IDependency dependency) { this.dependency = dependency; } public void FubarBaz() { dependency.Baz = "fubar"; } } I could also implement this as: class FooStatic { public static void F...

Serializing immutable java classes to actionscript with LCDS

Hi, I've got a complex object which is being managed by the LCDS DataServices data management and being created/updated etc using custom assemblers. The vast majority of the object hierarchy is being serialized/deserialized correctly but I've hit a stumbling block when it comes to serializing immutable java classes. In a java only worl...