module ColistQuestion where import Prelude hiding (iterate) -- produces an infinite list iterate :: (a -> a) -> a -> [a] iterate f a = a : iterate f (f a) -- produces a possibly infinite list iterate1 :: (a -> Maybe a) -> a -> [a] iterate1 f a = a : case f a of Just a1 -> iterate1 f a1 Nothing -> [] -- call this a "transcript"; like a list with an "answer" data T e a = e :<< T e a | V a -- produces an infinite transcript a' la iterate iterT :: (e -> e) -> e -> T e a iterT f e = e :<< iterT f (f e) -- produces a possibly infinite transcript a' la iterate1 iterT1 :: (e -> Either e a) -> e -> T e a iterT1 f e = e :<< case f e of Left e1 -> iterT1 f e1 Right a -> V a