Unexpected behavior from Data.List.groupBy
I was hoping that
let notBoth1 a b = not (a == 1 && b == 1) in groupBy notBoth1 [1,1,2,3,1,1,4,5,6,1]
would give me
but instead I get
It seems that groupBy assumes transitivity in the argument function. I have a new implementation that does not make this assumption. Of course, the implications of changing this function's behavior are troubling.
groupBy' :: (a -> a -> Bool) -> [a] -> [[a]] groupBy' p (x : xs) = go [x] xs where go (x : xs) (y : zs) | p x y = go (y : x : xs) zs go g (y : zs) = reverse g : go [y] zs go g  = [reverse g]