[Haskell] partition in Data.List bug

Koji Nakahara yu- at div.club.ne.jp
Thu Feb 5 05:04:27 EST 2004


Hi, 

I've encountered a bug of partition in Data.List shipped with
ghc-6.2 and hugs(Nov 2002)
It cannot work with an infinite list.

Example:
	> partition (==0) (cycle [0,1])
	does not return and so
 	not conform to the specification in the Haskell 98 and the library document.  

I found some discussion on this bug in the haskell mailing-list archive,
e.g. http://www.mail-archive.com/haskell@haskell.org/msg07789.html

Is there some good reason not to change this behaviour?
(And if it is, I think that the library document should be fixed.)

Patch:
--- List.hs.orig        Thu Feb  5 04:15:59 2004
+++ List.hs     Thu Feb  5 04:16:31 2004
@@ -240,8 +240,8 @@
 {-# INLINE partition #-}
 partition p xs = foldr (select p) ([],[]) xs

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

 -- @mapAccumL@ behaves like a combination
 -- of  @map@ and @foldl@;

---
Koji Nakahara


More information about the Haskell mailing list