FUNARCH 2024 Workshop
FUNARCH 2024 will be co-colocated with ICFP 2024 in Milan on September 6th 2024!

More events
↩ Functional Software Architecture Overview

Immutability

Principle

Object-oriented and procedural programming treat all data as a combination of two things: a place (in memory) and a value that occupies this place. In functional programming we omit the first concept and talk about immutable values directly. This makes programming way simpler because it frees the programmer from thinking in terms of resource and state management and allows them to think in terms of their domain. These advantages carry over from functional programming to functional software architecture. We avoid mutable state no matter the size of the structure.

Blabla und so weiter.

Implementations

Functional programming languages come with a wide array of immutable data types. The archetypical immutable data type is the linked list built of cons pairs.

              
                ;; The list 1, 2, 3
                (define alist
                  (cons 1 (cons 2 (cons 3 nil))))
              
            

If you want to change the head of alist from 1 to 99 and keep the rest as is, you can produce a new list by calling cons with 99 and the rest of the old list.

              
                ;; The list 99, 2, 3
                (define newlist
                  (cons 99 (rest alist)))