[Haskell-cafe] fmap vs. liftM

Henning Thielemann lemming at henning-thielemann.de
Wed Feb 6 08:50:11 EST 2008


On Tue, 5 Feb 2008, Felipe Lessa wrote:

> On Feb 5, 2008 6:06 PM, Dan Weston <westondan at imageworks.com> wrote:
> > Can you do this with a GHC rule? Something like:
> >
> > {-# RULES
> >        "join_dot_fmap_return/id"  forall x . join (fmap return x) = x
> > #-}
> >
> > Dan
>
> I guess this would make use of the rule (otherwise the transformation
> would change the code's semantic) but would not enforce that the rule
> itself is valid (which is undecidable).

I have already thought about (ab)using GHC rules for forcing programmers
to take care. :-) That is, if the rule would be stated as above, then
programmers _have_ to ensure that the law is satisfied, and the optimizer
will penalize violations of the rules with non-working code.


More information about the Haskell-Cafe mailing list