[commit: ghc] master: Make tails a good producer (#9670) (7e73595)

git at git.haskell.org git at git.haskell.org
Thu Oct 16 07:45:42 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7e735950a44f7f3c34319ea65631e11e52eb68a7/ghc

>---------------------------------------------------------------

commit 7e735950a44f7f3c34319ea65631e11e52eb68a7
Author: David Feuer <David.Feuer at gmail.com>
Date:   Thu Oct 16 09:44:25 2014 +0200

    Make tails a good producer (#9670)
    
    Reviewed By: nomeata, austin
    Differential Revision: https://phabricator.haskell.org/D325


>---------------------------------------------------------------

7e735950a44f7f3c34319ea65631e11e52eb68a7
 libraries/base/Data/OldList.hs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libraries/base/Data/OldList.hs b/libraries/base/Data/OldList.hs
index ad2c510..ff85154 100644
--- a/libraries/base/Data/OldList.hs
+++ b/libraries/base/Data/OldList.hs
@@ -787,9 +787,12 @@ inits                   = map toListSB . scanl' snocSB emptySB
 -- Note that 'tails' has the following strictness property:
 -- @tails _|_ = _|_ : _|_@
 tails                   :: [a] -> [[a]]
-tails xs                =  xs : case xs of
-                                  []      -> []
-                                  _ : xs' -> tails xs'
+{-# INLINABLE tails #-}
+tails lst               =  build (\c n ->
+  let tailsGo xs = xs `c` case xs of
+                             []      -> n
+                             _ : xs' -> tailsGo xs'
+  in tailsGo lst)
 
 -- | The 'subsequences' function returns the list of all subsequences of the argument.
 --



More information about the ghc-commits mailing list