
4 Mar
2018
4 Mar
'18
9:32 a.m.
I found that in base [1] 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 {-# RULES "++" [~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=[]. Any thoughts? [1] http://hackage.haskell.org/package/base-4.10.1.0/docs/src/GHC.Base.html#%2B%... Cheers Ben