<div dir="ltr"><div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">> In particular, if<span> </span></span><code style="margin:0px;padding:0px;font-family:monospace;line-height:16.12px;color:rgb(0,0,0);font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Functor.html#v:fmap" style="margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84)">fmap</a></code><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>is an expensive operation, it is likely better to use<span> </span></span><code style="margin:0px;padding:0px;font-family:monospace;line-height:16.12px;color:rgb(0,0,0);font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:liftA2" style="margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84)">liftA2</a></code><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>than to<span> (</span></span><code style="margin:0px;padding:0px;font-family:monospace;line-height:16.12px;color:rgb(0,0,0);font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Functor.html#v:fmap" style="margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84)">fmap</a></code><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>over the structure </span><b><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">and then use </span><code style="margin:0px;padding:0px;font-family:monospace;line-height:16.12px;color:rgb(0,0,0);font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:-60--42--62-" style="margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84)"><*></a>)</code></b><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">. </span>(emphasis and parens added).</div><div><br></div><div>Consider any data constructor that has a strict spine and look at</div><div><br></div><div>f <$> m <*> n</div><div><br></div><div>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.</div><div><br></div><div>-Edward </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 30, 2018 at 4:42 AM, Damien BIHEL <span dir="ltr"><<a href="mailto:biheldamien@gmail.com" target="_blank">biheldamien@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>In the documentation <a href="http://hackage.haskell.org/package/base-4.10.1.0/docs/Control-Applicative.html#v:liftA2" target="_blank">here</a> it's written that for some functors liftA2 has better performance than fmap. Does anyone have any examples ?<br><br></div>Regards,<span class="HOEnZb"><font color="#888888"><br><div><br>-- <br>Damien Bihel<br>R&D (Research & Development) Engineer at ELRA (European Language Resources Association)<br>E-Mail: <a href="mailto:biheldamien@gmail.com" target="_blank">biheldamien@gmail.com</a><br></div></font></span></div>
<br>______________________________<wbr>_________________<br>
Haskell mailing list<br>
<a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell</a><br>
<br></blockquote></div><br></div>