> In particular, if fmap <http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Functor.html#v:fmap> is an expensive operation, it is likely better to use liftA2 <http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:liftA2> than to (fmap <http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Functor.html#v:fmap> over the structure *and then use <*> <http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:-60--42--62->)* . (emphasis and parens added).
Consider any data constructor that has a strict spine and look at f <$> m <*> n This has to walk `m` twice. Once for the fmap on the first argument, and once for the <*>, but the liftA2 version can walk `m` once fusing things together. -Edward On Tue, Jan 30, 2018 at 4:42 AM, Damien BIHEL <biheldam...@gmail.com> wrote: > In the documentation here > <http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:liftA2> > it's written that for some functors liftA2 has better performance than > fmap. Does anyone have any examples ? > > Regards, > > -- > Damien Bihel > R&D (Research & Development) Engineer at ELRA (European Language Resources > Association) > E-Mail: biheldam...@gmail.com > > _______________________________________________ > Haskell mailing list > Haskell@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell > >
_______________________________________________ Haskell mailing list Haskell@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell