{-
 - Opgaver på ugeseddel 9 til kapitel 19
 -}
module Uge09_19 where

-- strict (p. 427)
strict :: (a -> b) -> a -> b
strict f x = seq x (f x)
-- (dvs. evaluér x først og afleverer dernæst udtrykket f x)

-- -- foldr (p. 426)
-- foldr :: (a -> b -> b) -> b -> [a] -> b
-- foldr f st []     = st
-- foldr f st (x:xs) = f x (foldr f st xs)
--

-- foldl' (p. 428ø)
foldl' :: (a -> b -> a) -> a -> [b] -> a
foldl' f st []     = st
foldl' f st (x:xs) = strict (foldl' f) (f st x) xs


-- Opgave 19.20

reverseR = foldr  (\x y -> y ++ [x]) []
reverseL = foldl' (\x y -> y:x) []

-- Opgave 19.21
-- Opgave 19.23

