1 data List a = Nil | Cons a (List a)
\r
5 build :: (forall a. a -> (b -> a -> a) -> a) -> List b
\r
9 foldr :: (a -> b -> b) -> b -> List a -> b
\r
10 foldr cons nil Nil = nil
\r
11 foldr cons nil (Cons h t) = cons h (foldr cons nil t)
\r
15 singleton :: a -> List a
\r
16 singleton x = build (\nil cons -> cons x nil)
\r
20 last :: List a -> a -> a
\r
21 last l def = foldr (\x _ -> x) def l
\r
23 main = last (singleton "Hello") "Foo"
\r