<p>Yes, composition is still associative, but is not <em>function</em> composition anymore. Instead it is <em>morphism</em> composition in a Kleisli category of a monad that captures the computational effects. The nLab page on <a href="https://ncatlab.org/nlab/show/monad+%28in+computer+science%29" rel="nofollow noreferrer">monads in computer science</a> describes the basic ideas and is probably a suitable starting point.</p>

CC BY-SA 4.0
2021-09-21T19:59:24.800Z
2021-09-21T19:59:24.800Z
Andrej Bauer
<p>We know that function composition is associative in theoretical programming languages such as STλC, and pure functional programming languages such as Haskell. Is the same true for languages where functions can mutate state and have all sorts of side effects?</p>

<functional-programming><function><imperative-programming>
Is function composition associative in non-pure programming languages?
Michele De Pascalis
# Is function composition associative in non-pure programming languages?

(Asked by: username_0 on 2021-09-21)

We know that function composition is associative in theoretical programming languages such as STλC, and pure functional programming languages such as Haskell. Is the same true for languages where functions can mutate state and have all sorts of side effects?

**Tags:** functional-programming, function, imperative-programming

---

## 1 answers

### Answer by username_1 on 2021-09-21. Score: 2 | Accepted answer

Yes, composition is still associative, but is not *function* composition anymore. Instead it is *morphism* composition in a Kleisli category of a monad that captures the computational effects. The nLab page on [monads in computer science](https://ncatlab.org/nlab/show/monad+%28in+computer+science%29) describes the basic ideas and is probably a suitable starting point.


---

