dropWhileRev
Jonathan Cast
jcast at ou.edu
Sun Aug 7 10:10:03 EDT 2005
Henning Thielemann <lemming at henning-thielemann.de> wrote:
> Is this function worth to be added to Data.List?
>
>
> {-| Remove the longest suffix of elements satisfying the predicate.
> In contrast to 'reverse . dropWhile p . reverse'
> this works for infinite lists, too. -}
> dropWhileRev :: (a -> Bool) -> [a] -> [a]
> dropWhileRev p =
> foldr (\x xs -> if p x && null xs then [] else x:xs) []
Quick query: this function only delivers partial lists from partial
lists; hence, it only returns partial lists and infinite lists from
infinite lists
(In particular, it is not true that, if (exists n. take n (dropWhileRev
p xn) /= take n xn) then (dropWhileRev p xn `isPrefixOf` xn = True).
Prelude> let dropWhileRev p = foldr (\x xs -> if p x && null xs then [] else x:xs) []
Prelude> dropWhileRev (const True) (repeat 'c')
"*** Exception: stack overflow
Prelude> dropWhileRev (\n -> n `mod` 2 == 0) ([1..3]++repeat 2)
[1,2,3*** Exception: stack overflow
Prelude>
What do you mean by ``works for inifinite lists''?
Jon Cast
More information about the Libraries
mailing list