Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Last active December 25, 2015 03:09
Show Gist options
  • Save thomwiggers/6907727 to your computer and use it in GitHub Desktop.
Save thomwiggers/6907727 to your computer and use it in GitHub Desktop.
foldr :: (a b -> b) b [a]
foldr op e [] = e
foldr op e (x:xs) = op x (foldr op e xs)
foldr op 0 [1,2] = op 1 (foldr op 0 [2])
= op 1 (op 2 (foldr op 0 []))
= op 1 (op 2 0)
Start = fiets a b
fiets = max -- max is een functie die van twee argumenten de grootste pakt
--Herschrijfschema:
Start = fiets a b
= max a b
--Nu met argumenten voor fiets:
fiets a b = max
Start = fiets a b
= max
VoorbeeldMetIf :: Bool -> String
VoorbeeldMetIf voorwaarde = if voorwaarde "AlsVoorwaardeTrueWordtDitUitgevoerd" "AlsVoorwaardeFalsewordtDitUitgevoerd"
-- met (haskell-stijl) commentaar erbij voor de duidelijkheid
VoorbeeldMetIf voorwaarde = if voorwaarde {- then -} "AlsVoorwaardeTrueWordtDitUitgevoerd" {- else -} "AlsVoorwaardeFalsewordtDitUitgevoerd"
takeWhile` :: (a -> Bool) -> [a] -> [a]
takeWhile` predicaat lijst = foldr (functie die iets met 'predicaat' doet) 'basecase' lijst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment