Listing 1: Beispieltiere, die mit Gleichungen Namen bekommen
a1 = Dillo Alive 10 -- lebendiges Gürteltier, 10kg a2 = Parrot "Hello!" 2 -- Papagei mit Begrüßung, 2kg a3 = Dillo Dead 12 -- totes Gürteltier, 12kg a4 = Parrot "Goodbye!" 1 -- Papagei mit Verabschiedung, 1kg

Listing 2: Folge von Zustandstransformationen
feedAndDie d =  let d2 = feed 2 d      d3 = feed 3 d2      d4 = runOver d3
  in d4


Listing 3: Vorrat beim Füttern mitführen
type Stash = Weight  feedFromStash :: Weight -> Animal Weight -> Stash -> (Animal Weight, Stash) feedFromStash amount animal stash =  if amount <= stash  then (feed amount animal, stash – amount)  else (feed stash animal, 0)

Listing 4: Futter aus Vorrat entfernen
removeFromStash :: Weight -> Stash -> (Weight, Stash) removeFromStash amount stash =  let realAmount = min amount stash  in (realAmount, stash – realAmount)

Listing 5: Futter aus Vorrat entnehmen, als Stash Transformer
removeFromStashST :: Weight -> ST Weight removeFromStashST amount =  ST (\ stash →        let realAmount = min amount stash        in (realAmount, stash – realAmount))


Listing 6:Komposition von Stash Transformer
composeST :: ST result1 -> (result1 -> ST result2) -> ST result2 composeST transformer next = ST (\ stash →       let (result1, stash1) = applyST transformer stash       in applyST (next result1) stash1)


Listing 7: Aus Vorrat füttern, als Stash Transformer
feedFromStashST :: Weight -> Animal Weight -> ST (Animal Weight) feedFromStashST amount animal =  composeST (removeFromStashST amount)    (\ realAmount -> feedST realAmount animal)

Listing 8: Stash Transformer mit Monaden-Syntax
feedFromStashST :: Weight -> Animal Weight -> ST (Animal Weight) feedFromStashST amount animal =  do realAmount <- removeFromStashST amount     feedST realAmount animal

Listing 9: Tiere auf dem texanischen Highway, Idris-Version
data Liveness = Dead | Alive  Weight : Type Weight = Int
 data Animal : Type -> Type where  Dillo : Liveness -> weight -> Animal weight  Parrot : String -> weight -> Animal weight  a1 : Animal Int a1 = Dillo Alive 10 a2 : Animal Int a2 = Parrot "Hello!" 2 a3 : Animal Int a3 = Dillo Dead 12 a4 : Animal Int a4 = Parrot "Goodbye!" 1  Transformer : Type -> Type Transformer state = state -> state  feed : Num weight => weight -> (Transformer (Animal weight)) feed amount (Dillo liveness weight) = Dillo liveness (weight + amount) feed amount (Parrot sentence weight) = Parrot sentence (weight + amount)  runOver : Animal weight -> Animal weight runOver (Dillo liveness weight) = Dillo Dead weight runOver (Parrot sentence weight) = Parrot "" weight

Listing 10: Aus Vorrat füttern, als Effekt in Idris ausgedrückt
feedFromStash : Weight -> Animal Weight -> Eff (Animal Weight) [STASH] feedFromStash amount animal =  do realAmount <- removeFromStash amount     feedF realAmount animal


Listing 11: Debug-Output mit STDIO-Effekt
feedFromStash : Weight -> Animal Weight -> Eff (Animal Weight) [STASH, STDIO] feedFromStash amount animal =  do realAmount <- removeFromStash amount     putStr ("feeding " ++ show realAmount)     feedF realAmount animal

Listing 12: Nichtdeterminismus als Effekt
feedFromStashND : Weight -> Weight -> Animal Weight -> Eff (Animal Weight) [STASH, SELECT] feedFromStashND lowAmount highAmount animal =  do amount <- select [lowAmount .. highAmount]     realAmount <- removeFromStash amount     feedF realAmount animal


Listing 13: Definition eines neuen Effekts
STASH : EFFECT STASH = MkEff Stash StashT  removeFromStash : Weight -> Eff Weight [STASH] removeFromStash amount = call (RemoveFromStash amount)


Listing 14: Implementierung des STASH-Effekts
Handler StashT monad where  handle stash (RemoveFromStash amount) next =    let realAmount = min stash amount    in next realAmount (stash – realAmount)