Why is partition no good list producer?

Jan Scheffczyk jan at informatik.unibw-muenchen.de
Wed Feb 25 13:52:05 EST 2004

> what you observe is possibly related to this:
> http://www.mail-archive.com/haskell@haskell.org/msg07508.html

Although I'm adressing purely the problem of runtime, you are probably 
At least the implementation of partition is still defined in terms of 
foldr (from Data.List in ghc 6.2):

-- > partition p xs == (filter p xs, filter (not . p) xs)

partition               :: (a -> Bool) -> [a] -> ([a],[a])
{-# INLINE partition #-}
partition p xs = foldr (select p) ([],[]) xs

select p x (ts,fs) | p x       = (x:ts,fs)
                   | otherwise = (ts, x:fs)

Is the above strict version of partition more suitable for other 
optimizations than my partition/foldr case??


More information about the Glasgow-haskell-users mailing list