[Git][ghc/ghc][master] Elaborate on performance properties of Data.List.++

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Jun 3 20:50:39 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
b2c745db by Bodigrim at 2023-06-03T16:50:23-04:00
Elaborate on performance properties of Data.List.++

- - - - -


1 changed file:

- libraries/base/GHC/Base.hs


Changes:

=====================================
libraries/base/GHC/Base.hs
=====================================
@@ -1461,8 +1461,13 @@ The rules for map work like this.
 --
 -- If the first list is not finite, the result is the first list.
 --
--- WARNING: This function takes linear time in the number of elements of the
--- first list.
+-- This function takes linear time in the number of elements of the
+-- __first__ list. Thus it is better to associate repeated
+-- applications of '(++)' to the right (which is the default behaviour):
+-- @xs ++ (ys ++ zs)@ or simply @xs ++ ys ++ zs@, but not @(xs ++ ys) ++ zs at .
+-- For the same reason 'Data.List.concat' @=@ 'Data.List.foldr' '(++)' @[]@
+-- has linear performance, while 'Data.List.foldl' '(++)' @[]@ is prone
+-- to quadratic slowdown.
 
 (++) :: [a] -> [a] -> [a]
 {-# NOINLINE [2] (++) #-}



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b2c745db6a817993dcef03551243a2fd2b3ea756

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b2c745db6a817993dcef03551243a2fd2b3ea756
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230603/b49dce04/attachment.html>


More information about the ghc-commits mailing list