map f (x:xs) = f x : (map f xs) map f [] = [] foldr f e (x:xs) = f x (foldr f e xs) foldr f e [] = e add l m = ifthenelse (fst3 map f l = ifthenelse (fst3 l) (append (f (snd3 l)) (map f (thd3 l))) (emptList) emptList = 3pair false id id append x l = 3pair true x l