Adding an ignore function to Control.Monad

David Menendez dave at zednenem.com
Thu Jun 11 17:00:58 EDT 2009


On Thu, Jun 11, 2009 at 4:26 PM, Felipe Lessa<felipe.lessa at gmail.com> wrote:
> On Thu, Jun 11, 2009 at 04:14:22PM -0400, David Menendez wrote:
>> Aside from assertions that this is a bad thing because you say so,
>> what evidence do we have that this is a problem?
>
> The wiki mentions the problem with forgetting the results of an
> operation.

This is exactly what I'm talking about. That page is written almost
entirely by Henning
Thielemann, but because it's on the official Haskell wiki, it seems
authoritative.

> Another problem is using functions that needlessly
> produce results because you're interested in the side effects
> only.  For example,
>
>  do mapM something1 list
>     something2

I do agree that someone is less likely to accidently write

do ignore (mapM something1 list)
    something2

But this is generally less dangerous than, say, using foldl instead of foldl'.

> (Hmmm, would something like
>
>  {-# RULES "mapM/mapM_" mapM = mapM_ #-}
>
> work nicely?)

Unfortunately, I don't think that rule would ever be applied, because
the types of mapM and mapM_ don't match.

You could have a rule that transformed ignore (mapM x y) to mapM_ x y, though.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Libraries mailing list