Menu

1 / 5

Pure Functions, Functors, Applicatives & Monads

DEV Community: haskell·conjurer·5 days ago
#FVRP1e4p
#devtohaskell#devto#dev#lego#instructions
Reading 0:00
15s threshold

Think of any wrapped context in Haskell (like Maybe ) as a sealed plastic Lego storage box:

Data (like the number 5) is a red Lego block inside.

A Pure Function is an instruction sheet ("Attach a blue block").

Pure Function

No Lego boxes here—just instructions applied to raw blocks sitting on desk.

It only looks at the inputs explicitly passed. No database calls, no reading system clocks, no side effects. The same input always yields the exact same output.

addOne :: Int -> Int addOne x = x + 1

Enter fullscreen mode

Exit fullscreen mode

Functor ( fmap / <$> )

Got some building instructions, but the Lego block is locked inside a sealed plastic box.

A Functor acts like a pair of reach-in gloves: it applies the instructions to the wrapped block without breaking the box.

fmap ( + 1 ) ( Just 5 ) -- Returns Just 6

Enter fullscreen mode

Exit fullscreen mode

Applicative (<*>)

What if both instructions AND Lego blocks are sealed in separate plastic boxes?

An Applicative opens both boxes, applies the…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.