[GHC] #9623: Use Data.List.dropWhileEnd
GHC
ghc-devs at haskell.org
Sun Sep 21 20:24:52 UTC 2014
#9623: Use Data.List.dropWhileEnd
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: task | Status: new
Priority: normal | Milestone: 7.10.1
Component: libraries | Version: 7.8.3
(other) | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Easy (less than 1
Unknown/Multiple | hour)
Type of failure: | Blocked By:
None/Unknown | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by dfeuer):
There's a separate potential issue I don't think is likely to affect any
of these uses: `dropWhileEnd` is defined like this:
{{{#!hs
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
}}}
This is (relatively) strict in the elements of the list and (relatively)
lazy in its spine. This is the opposite of the `reverse . dropWhile p .
reverse` behavior. There should (according to some theory) also be a
{{{#!hs
dropWhileEndLE :: (a -> Bool) -> [a] -> [a]
dropWhileEndLE p = foldr (\x xs -> if null xs && p x then [] else x : xs)
[]
}}}
that's the other way around. We could call such a thing `dropWhileEnd'`,
but that naming convention clashes with another pair of things that should
exist and don't:
{{{#!hs
takeWhileEnd :: (a -> Bool) -> [a] -> [a]
takeWhileEnd p = fst . foldr go ([], False)
where
go x (rest, done)
| not done && p x = (x:rest, False)
| otherwise = (rest, True)
takeWhileEnd' p = fst . foldr go ([], False)
where
go x (rest, done)
| p x && not done = (x:rest, False)
| otherwise = (rest, True)
}}}
`takeWhileEnd'` is strict in both the elements and the spine (assuming a
strict predicate), while `takeWhileEnd` is only strict in the spine.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9623#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list