Mutability in functional programming?

There are of course many ways functional languages address this issue Different data structures - many data structures can be implemented in a purely functional manner, with the same algorithmic complexity as imperative versions. Probably the most well-known work in this area is Chris Okasaki's Purely Functional Data Structures but there are many other resources as well. For Dijkstra's algorithm Martin Erwig s work on functional graphs is appropriate.

See this question as well Different algorithms - some algorithms have assumptions of mutability built-in, Quicksort is an example of this. In this case an alternative algorithm can be used that's more amenable to immutability Mutable state - every functional language can model functional state with a State monad. Most provide other forms of mutability as well, such as Haskell's ST monad and IORef's.

There are of course many ways functional languages address this issue. Different data structures - many data structures can be implemented in a purely functional manner, with the same algorithmic complexity as imperative versions. Probably the most well-known work in this area is Chris Okasaki's Purely Functional Data Structures, but there are many other resources as well.

For Dijkstra's algorithm, Martin Erwig's work on functional graphs is appropriate. See this question as well. Different algorithms - some algorithms have assumptions of mutability built-in, Quicksort is an example of this.In this case an alternative algorithm can be used that's more amenable to immutability.

Mutable state - every functional language can model functional state with a State monad. Most provide other forms of mutability as well, such as Haskell's ST monad and IORef's.

4 Sadly, research into data structures and algorithms best suited for lazy functional immutable languages lags behind that for strict imperative mutable languages. :-( – ephemient Jan 6 at 21:06.

Creating new immutable objects isn't nearly as expense as you might think, since large amounts of structural sharing can occur because the compiler KNOWS they can't change and thus can be safely shared. That said, using highly imperative algorithms with lots of mutable state in Haskell is a bit of a code smell.

The ST Monad lets you use mutable state internally, but present a pure external interface.

In ML derivatives (such as OCaml, SML, F#), there are "references", which can be used as mutable variables. In Haskell, this isn't cleanly handled. State is simply not covered by the usual "purely functional" style.

Pure FP languages deal with "eternal truths", and are thus not very suitable for working with "ephemeral truths" (although it can be done, definitely). However, yes, sometimes we need mutable state. A language such as ATS incorporates linear types for handling destructive updates and safe resource manipulation.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions