Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 577
    • Merge requests 577
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13593
Closed
Open
Issue created Apr 19, 2017 by dsf@trac-dsf

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

[[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.

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]
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure IncorrectResultAtRuntime
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking