Hi L.Guo
Brent has replied with the right answer.
The definition of groupBy is below - the span in the where clause only
compares with the first element of the current sub-list:
-- | The 'groupBy' function is the non-overloaded version of 'group'.
groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy _ [] = []
groupBy eq (x:xs) = (x:ys) : groupBy eq zs
where (ys,zs) = span (eq x) xs
--
list1 = [7,3,5,9,6,8,3,5,4::Int]
Here are two more runs on your input with a wee bit less clutter. In
both cases there are 'spans' where the numbers increase and decrease -
this is because the operation is comparing the rest of the input
against the first element in the 'span' not consecutive elements.
*GroupBy Data.List> groupBy (<) list1
[[7],[3,5,9,6,8],[3,5,4]]
*GroupBy Data.List> groupBy (<=) list1
[[7],[3,5,9,6,8,3,5,4]]
Best wishes
Stephen
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe