-- lists type list { nil : list; cons : Any -> list -> list; }; def head := \l case l of { cons h _ := h }; def tail := \l case l of { cons _ t := t }; def null := \l case l of { nil := true; cons _ _ := false }; def map := \f \l case l of { nil := nil; cons h t := cons (f h) (map f t) }; def foldl := \f \acc \l case l of { nil := acc; cons h t := foldl f (f acc h) t }; def foldr := \f \acc \l case l of { nil := acc; cons h t := f h (foldr f acc t) }; def filter := \f \l case l of { nil := nil; cons h t := if f h then cons h (filter f t) else filter f t }; def rev := foldl (\acc \x cons x acc) nil; def gen := \n if n = 0 then nil else cons n (gen (n - 1)); def sum := \n foldl (+) 0 (gen n); def sum' := \n foldr (+) 0 (gen n); def foldl' := \f \acc \l if null l then acc else foldl' f (f acc (head l)) (tail l); def sum'' := \n foldl' (+) 0 (gen n); def writeLn := \x write x >> write "\n"; writeLn (gen 10) >> writeLn (rev (gen 10)) >> writeLn (filter (\x x > 5) (gen 10)) >> writeLn (rev (map (\x x - 1) (gen 10))) >> writeLn (sum 1000) >> writeLn (sum' 1000) >> writeLn (sum'' 1000)