Home/Blog

Effects, functionally

What are functional effects, really?

Functional effects can be used to model side effects in a purely functional program. When we think about what side effects are in a non-pure program we can say that they are all the other things that can happen besides passing around a value. Functional effects are a functional way to keep this separation of the effect and passing around a value.

Functional effects consist of:

Let’s look at some examples (from PureScript):

Partiality

data Maybe a = Nothing | Just a

Read-only context

data Reader r a = Reader (r -> a)

Read-write context

data State s a = State (s -> Tuple a s)

No effects

data Identity a = Identity a