[Haskell-cafe] Improvement suggestions

José Lopes jose.lopes at ist.utl.pt
Wed Aug 15 17:25:14 CEST 2012


Thank you.

On 15-08-2012 23:09, Twan van Laarhoven wrote:
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-- 
José António Branquinho de Oliveira Lopes
58612 - MEIC-A
Instituto Superior Técnico (IST), Universidade Técnica de Lisboa (UTL)
jose.lopes at ist.utl.pt




More information about the Haskell-Cafe mailing list