I have this code:
lado :: [([Char],Int)] -> [[Char]]
lado xs = [a | (a,b) <- xs]
I need to output this:
> lado [("A
You can use recursion to accomplish this:
lado :: [(a, Int)] -> [a]
-- base case
lado [] = []
-- take each of the non-zero elements then recurse
lado xs = map fst nonzero ++ lado subtracted
where
-- find elements with non-zero count
nonzero = filter (\x -> snd x > 0) xs
-- subtract one from the count for each of those elements
subtracted = map (\(x, n) -> (x, n - 1)) nonzero