collatz :: Int -> [Int]
collatz x = go id x []
where
go :: ([Int] -> [Int]) -> Int -> [Int] -> [Int]
go f 1 = f . (1:)
go f n =
if even n
then go (f . (n:)) (n `div` 2)
else go (f . (n:)) (3 * n + 1)
By the way, it is a full blown OS.