Gather first letter from each string in a list of strings I'm learning Haskell on my own, and I'm wondering if this is idiomatic Haskell.

In particular: is it a common pattern to "wrap" the result in a list in order to make a function total? (that's what I ended up doing to ensure the function was total and no compiler warnings about not matching a pattern).

safeHead :: [a] -&gt; Maybe a
safeHead []     = Nothing
safeHead (x:_)  = Just x

firstLetters :: [String] -&gt; [Char]
firstLetters ss = concat $
                     map (\s -&gt; case safeHead s of
                                Nothing -&gt; []
                                Just c  -&gt; [c]) ss
Well a few thoughts, of all String = [Char] so we could really give the signature

firstLetters :: [String] -&gt; String


Whether you think this is better is a matter of taste. Second, you should take a look at

Data.Maybe.mapMaybe :: (a -&gt; Maybe b) -&gt; [a] -&gt; [b]


It's exactly what you'd expect, it applies a function to Maybes and prunes out the Nothings. This simplifies the slightly ugly concat bit.

 firstLetters = mapMaybe safeHead


Much clearer :) In the interest of teaching you to fish, here's how I found the name of mapMaybe