Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Alex D
GHC
Commits
4e1dfc37
Commit
4e1dfc37
authored
Oct 01, 2014
by
David Feuer
Committed by
Joachim Breitner
Oct 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make scanr a good producer and consumer
This fixes #9355.
parent
488e95b4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
libraries/base/GHC/List.lhs
libraries/base/GHC/List.lhs
+18
-0
libraries/base/changelog.md
libraries/base/changelog.md
+2
-0
No files found.
libraries/base/GHC/List.lhs
View file @
4e1dfc37
...
@@ -229,11 +229,29 @@ foldr1 _ [] = errorEmptyList "foldr1"
...
@@ -229,11 +229,29 @@ foldr1 _ [] = errorEmptyList "foldr1"
--
--
-- > head (scanr f z xs) == foldr f z xs.
-- > head (scanr f z xs) == foldr f z xs.
{-# NOINLINE [1] scanr #-}
scanr :: (a -> b -> b) -> b -> [a] -> [b]
scanr :: (a -> b -> b) -> b -> [a] -> [b]
scanr _ q0 [] = [q0]
scanr _ q0 [] = [q0]
scanr f q0 (x:xs) = f x q : qs
scanr f q0 (x:xs) = f x q : qs
where qs@(q:_) = scanr f q0 xs
where qs@(q:_) = scanr f q0 xs
{-# INLINE [0] strictUncurryScanr #-}
strictUncurryScanr :: (a -> b -> c) -> (a, b) -> c
strictUncurryScanr f pair = case pair of
(x, y) -> f x y
{-# INLINE [0] scanrFB #-}
scanrFB :: (a -> b -> b) -> (b -> c -> c) -> a -> (b, c) -> (b, c)
scanrFB f c = \x (r, est) -> (f x r, r `c` est)
{-# RULES
"scanr" [~1] forall f q0 ls . scanr f q0 ls =
build (\c n -> strictUncurryScanr c (foldr (scanrFB f c) (q0,n) ls))
"scanrList" [1] forall f q0 ls .
strictUncurryScanr (:) (foldr (scanrFB f (:)) (q0,[]) ls) =
scanr f q0 ls
#-}
-- | 'scanr1' is a variant of 'scanr' that has no starting value argument.
-- | 'scanr1' is a variant of 'scanr' that has no starting value argument.
scanr1 :: (a -> a -> a) -> [a] -> [a]
scanr1 :: (a -> a -> a) -> [a] -> [a]
...
...
libraries/base/changelog.md
View file @
4e1dfc37
...
@@ -77,6 +77,8 @@
...
@@ -77,6 +77,8 @@
second argument, so that the fusion RULES for it do not change the
second argument, so that the fusion RULES for it do not change the
semantics. (#9596)
semantics. (#9596)
*
`scanr`
now takes part in list fusion (#9355)
## 4.7.0.1 *Jul 2014*
## 4.7.0.1 *Jul 2014*
*
Bundled with GHC 7.8.3
*
Bundled with GHC 7.8.3
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment