[GHC] #13593: Unexpected behavior from Data.List.groupBy
GHC
ghc-devs at haskell.org
Wed Apr 19 20:27:54 UTC 2017
#13593: Unexpected behavior from Data.List.groupBy
-------------------------------------+-------------------------------------
Reporter: dsf | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Core | Version: 8.0.1
Libraries |
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: Incorrect result
Unknown/Multiple | at runtime
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
I was hoping that
{{{#!hs
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
{{{
[[1],[1,2,3,1],[1,4,5,6,1]]
}}}
but instead I get
{{{
[[1],[1,2,3],[1],[1,4,5,6],[1]]
}}}
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.
{{{#!hs
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]
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13593>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list