I was assigned to write a piece of Haskell code that makes an infinite list containing increasing numbers of 'a's.
My first thought was to write it as a list comprehension like this:
aStar = [replicate n 'a' | n <- [0..]]
But when I asked my professor he said I should use explicit recursion so I came up with this:
aStar :: [String] --repeats a string from 0 aStar = repeat' 0 'a' repeat' :: Int -> Char -> [String] repeat' n x = [cycle' x n] ++ repeat' (n + 1) x where cycle' _ 0 = "" cycle' y z = [y] ++ cycle' y (z - 1)
Is there a shorter way to do it?