99 Haskell Problems
(**) Decode a run-length encoded list.
Given a run-length code list generated as specified in problem 11. Construct its uncompressed version.
Example in Haskell:
P12> decodeModified [Multiple 4 'a',Single 'b',Multiple 2 'c', Multiple 2 'a',Single 'd',Multiple 4 'e'] "aaaabccaadeeee"
decodeModified :: (Eq a) => [CountElem a] -> [a] decodeModified  =  decodeModified (x:xs) = (convertStr x)++(decodeModified xs) convertStr :: (Eq a) => CountElem a -> [a] convertStr (Single s) = buildstr 1 s convertStr (Multiple n s) = buildstr n s buildstr :: (Eq a) => Int -> a -> [a] buildstr n s | n == 0 =  | otherwise = s:(buildstr (n-1) s)
A more simple solution would be to use concatMap as shown in the solution of the problem.
decodeModified :: [CountElem a] -> [a] decodeModified = concatMap decodeHelper where decodeHelper (Single x) = [x] decodeHelper (Multiple n x) = replicate n
:t concatMap concatMap :: (a -> [b]) -> [a] -> [b]