Hi,

Tom asked why

head $ fst $ partition  (==1) [0..]

does not terminate. This is again because of the semantics of pattern matching with regard to pairs. The definition of partition from the Prelude is
partition               :: (a -> Bool) -> [a] -> ([a],[a])
partition p xs           = foldr select ([],[]) xs
                         where select x (ts,fs) | p x       = (x:ts,fs)
                                                | otherwise = (ts,x:fs)

Now select is strict in its second argument. �You get a less strict partition by

partition p xs           = foldr select ([],[]) xs
                         where select x ~(ts,fs) | p x       = (x:ts,fs)
                                                 | otherwise = (ts,x:fs)

This is equivalent to the one given by Tom.

Greetings,

Carsten

---
Carsten Schultz, Fachbereich Mathematik, FU Berlin
http://www.math.fu-berlin.de/~cschultz/
"To match the silent eloquence of the created world 
 I have had to learn to speak."  Jeanette Winterson

Reply via email to