[Haskell-cafe] missing optimization for (++)
ben.franksen at online.de
Sun Mar 4 09:32:50 UTC 2018
I found that in base  we have
(++)  ys = ys
(++) (x:xs) ys = x : xs ++ ys
I had expected there to be a clause
(++) xs  = xs
at the top, which would avoid the list traversal in this common case.
Is this somehow magically taken care of by the
"++" [~1] forall xs ys. xs ++ ys = augment (\c n -> foldr c n xs) ys
? No, inlining @augment g xs = g (:) xs@ gives me
(\c n -> foldr c n xs) (:) ys
= foldr (:) ys xs
which still traverses xs even if ys=.
More information about the Haskell-Cafe