Proposal: Add a strict version of <$> for monads

Johan Tibell johan.tibell at gmail.com
Thu Dec 19 19:01:01 UTC 2013


We've reached the end of the discussion period. Most seemed in favor. Those
who suggested adding a new type class for these kind of functors, do you
feel OK not doing that (and use Monad =>) with the argument that this
distinction is probably too fine grained and having a separate class (which
people need to implement) would probably be more of a pain than it's worth?

-- Johan



On Sat, Nov 30, 2013 at 7:41 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:

> On 2013-11-30 at 12:05:06 +0100, Roman Cheplyaka wrote:
> > * Nicolas Trangez <nicolas at incubaid.com> [2013-11-30 02:11:02+0100]
> >> I'm without a doubt overlooking something, but couldn't this be (otoh)
> >>
> >>     fmap' :: Functor f => (a -> b) -> f a -> f b
> >>     fmap' f = fmap (strictify f)
> >>       where
> >>         strictify s = (($!) id) . s
>
> > No. Evaluation of your 'strictify' function will be delayed for the very
> > same reason that evaluation of 'f' is delayed in the first place.
> >
> > It doesn't matter what 'strictify' *does* if it's not even evaluated.
>
> jfyi, if compiled with
>
>   ghc -O2 -dsuppress-all -dsuppress-uniques -ddump-simpl
>
> it can be seen that fmap' is really almost the same as a plain fmap,
> except for an left-over eta-expansion which ghc doesn't optimize away:
>
> fmap' = \ @ a @ b @ f $dFunctor f1 -> fmap $dFunctor (\ x -> f1 x)
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131219/c9982962/attachment.html>


More information about the Libraries mailing list