[Haskell-cafe] missing optimization for (++)
Brandon Allbery
allbery.b at gmail.com
Mon Mar 5 22:24:35 UTC 2018
Generated code, sometimes including "deriving"-generated code.
On Mon, Mar 5, 2018 at 5:18 PM, Ben Franksen <ben.franksen at online.de> wrote:
> Am 05.03.2018 um 13:40 schrieb Li-yao Xia:
> > On 03/05/2018 07:13 AM, Ben Franksen wrote:
> >> Okay, okay, I got it. I did not think about strictness when I asked. The
> >> funny thing is that the two fusion rules combined, as explained by
> >> Josef, seem to cause this shortcut to be taken. But that can't be true
> >> because (++) really is non-strict, I tested that, with -O2. How do you
> >> explain that?
> >
> > Rewrite rules apply at compile time and don't force any computation.
> > The second rule fires only if the second argument of (++) is
> > syntactically []. Otherwise the code doesn't change, and strictness is
> > preserved.
>
> Thanks, yet another thing learned. So
>
> let ys = [] in xs ++ ys
>
> will traverse the spine of xs but
>
> xs ++ []
>
> will not. Interesting.
>
> (But who writes something like "xs ++ []" in a real program?)
>
> Cheers
> Ben
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180305/57102f86/attachment.html>
More information about the Haskell-Cafe
mailing list