-- Carsten Schuermann -- Lecture 4 : Lists / Functions / Lazyness module Lists where -- a non-terminating function run :: Float -> Float run x = run x -- two lists x :: [Float] x = run 4.0 : 7.11 : [] x' :: [Float] x' = [4.0, 7.11] y :: [Float] y = 5.0 : 5.0 : [] hx = head x tx = tail x -- append z = x ++ y -- adding elements of a list add x = case x of [] -> 0.0 h : t -> h + (add t) -- using functions. add' = \x -> case x of [] -> 0.0 h : t -> h + (add' t) -- making it even more abstract fold' = \l -> \c -> \f -> case l of [] -> c h : l' -> f (h, fold' l' c f) -- where is the mistake fold = \l -> \c -> \f -> case l of [] -> c h : l' -> f h (fold l' c f)