HASKELL MONSTER

— A Bestiary of Functional Beasts —

Begin Quest
LV
HP256/256
MP42
EXP1337

THE BESTIARY

Below lie the cataloged creatures of the Haskell realm. Approach with care; each beast obeys the strict laws of types.

THE MAYBE

data Maybe a = Nothing | Just a
COMMON

A timid two-headed sprite. One head is empty, the other clutches a value. Tame it to banish null pointers from the kingdom forever.

  • HP40
  • ATK12
  • WEAKfromJust

THE LIST

data [] a = [] | a : [a]
COMMON

A serpentine recursive beast — its tail is forever another smaller serpent. Strict adventurers are devoured by its infinite cousins.

  • HP50
  • ATK15
  • WEAKhead []

THE FUNCTOR

fmap :: (a -> b) -> f a -> f b
RARE

A shape-shifting amorph. Whatever spell you cast on a value, the Functor can cast inside its container without breaking the vessel.

  • HP80
  • ATK22
  • WEAKidentity law

THE APPLICATIVE

(<*>) :: f (a -> b) -> f a -> f b
RARE

A four-armed sorcerer wielding both spell and target inside the same container. Lifts pure magic into context with a single gesture.

  • HP110
  • ATK34
  • WEAKcomposition

THE MONAD

(>>=) :: m a -> (a -> m b) -> m b
EPIC

A swirling vortex creature that swallows context and spits out chains of computation. Many adventurers spend years deciphering its three sacred laws.

  • HP180
  • ATK56
  • WEAKdo-notation

THE IO DRAGON

main :: IO ()
EPIC

Hoarder of side effects. Breathes terminal fire and tramples disk drives. Only the runtime itself dares to unleash its actions upon the world.

  • HP210
  • ATK64
  • WEAKunsafePerformIO

MONAD TRANSFORMER

newtype StateT s m a = StateT { … }
LEGENDARY

A chimera of stacked monads. Each layer guards a different power — state, reader, except. To wield it is to command an entire battalion of monsters in perfect formation.

  • HP320
  • ATK92
  • WEAKlift . lift . lift

THE LENS

type Lens' s a = forall f. Functor f => …
LEGENDARY

A crystal eye that pierces through nested records. Adjusts the deepest value of any structure without disturbing its surface. Forged in van Laarhoven's workshop.

  • HP280
  • ATK88
  • WEAKprofunctors

EVOLUTION PATH

Each monster grows from the last. Master one, and the next becomes vulnerable.

FUNCTOR

fmap :: (a -> b) -> f a -> f b

Stage I — learns to map.

APPLICATIVE

pure :: a -> f a

Stage II — learns to lift.

MONAD

(>>=) :: m a -> (a -> m b) -> m b

Stage III — learns to chain.

MONAD TRANSFORMER

StateT s (ReaderT r IO) a

Final form — commands armies.

TYPE BATTLE ARENA

Two type signatures enter. One unifies. CHOOSE THE SURVIVOR.

FIGHTER A
(Monad m) =>
m a -> (a -> m b) -> m b
VS
FIGHTER B
IO () ->
(a -> IO b) -> IO b

Which type wins under unification?

— awaiting verdict —

SUMMON SPELL

-- summon a Maybe
summon :: String -> Maybe Beast
summon "monad"  = Just theMonad
summon "dragon" = Just ioDragon
summon _        = Nothing

BESTIARY LAWS

  1. fmap id ≡ id
  2. fmap (g . f) ≡ fmap g . fmap f
  3. return a >>= k ≡ k a
  4. m >>= return ≡ m
haskell.monster — compiled in the year of the lazy thunk