[Haskell-cafe] Improvement suggestions

Twan van Laarhoven twanvl at gmail.com
Wed Aug 15 17:09:13 CEST 2012


On 15/08/12 17:01, José Lopes wrote:
> someFn docs =
>    return concat `ap` (sequence $ intersperse (return "\n") (map loop docs))

First of all, "return x `ap` y" = "x `fmap` y" or "x <$> y". fmap (or its infix 
synonym (<$>)) is the answer here, you could write:

     someFn docs = concat . intersperse "\n" <$> mapM loop docs

The function Data.List.intercalate is a compation of concat and intersperse, so 
you could write:

     someFn docs = intercalate "\n" <$> mapM loop docs

or, depending on your preference,

     someFn = fmap (intercalate "\n") . mapM loop


Twan



More information about the Haskell-Cafe mailing list