LiftA2 over fmap

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

LiftA2 over fmap

Damien BIHEL
In the documentation here 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: [hidden email]

_______________________________________________
Haskell mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell
Reply | Threaded
Open this post in threaded view
|

Re: LiftA2 over fmap

Edward Kmett-2
> In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to (fmap over the structure and then use <*>)(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 <[hidden email]> wrote:
In the documentation here 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: [hidden email]

_______________________________________________
Haskell mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell



_______________________________________________
Haskell mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell