id x is x
comp f g x is f(g x)
isnil x is x eq nil
until p f x is if p x then x else until p f(f x)
map f l is if isnil l then nil
else f x:map f xs where (x is head l)
where xs is tail l
fold m z l is if isnil l then z
else m x(fold m z xs) where (x is head l)
where xs is tail l
append l m is if isnil l then m
else x:append xs m where (x is head l)
where xs is tail l
reverse l is if isnil l then nil else append (reverse (tail l))(head l)
filter p l is if isnil l then nil
else if p x then x:filter p xs
else filter p xs where (x is head l)
where xs is tail l
sort p l is if isnil l then nil
else insert p (head l) (sort p (tail l))
where insert pp e ll is if isnil il then [e]
else if pp e (head ll)
then e:ll
else head ll:insert pp e (tail ll)
drop n l is if ~n>0 then l else if isnil l then nil else drop (n-1) (tail l)
take n l is if (n=0)|isnil l then nil
else x:take (n-1) xs where (x is head l)
where xs is tail l
at n l is if n=0 then head l else at (n-1) (tail l)
length l is if isnil l then 0 else 1+length (tail l)
init l is if isnil (tail l) then nil else head l:init (tail l)
iterate f x is x:iterate f(f x)
repeat x is xs x where xs x is x:tail x
cycle xs is xs1 xs where xs1 x is append x (xs1 x)
splitAt n l is if ~n>0 then []:l
else if isnil l then []:[]
else head l:head xs:tail xs where (xs is splitAt (n-1) (tail l))
takeWhile p l is if isnil l then nil
else if p l then x:takeWhile p xs
else nil where (x is head l)
where xs is tail l
sum is fold(+)0
product is fold(*)1
zipWith f x y is if isnil x then nil
else f hx hy:zipWith (f tx ty) where (hx is head x)
where (hy is head y)
where (tx is tail x)
where ty is tail y