Skip to content

Monad comprehensions, group by

Summary

I was reading https://gitlab.haskell.org/ghc/ghc/-/wikis/monad-comprehensions.

What happened to group by?

Steps to reproduce

box% ghci
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
Prelude> :set -XMonadComprehensions -XTransformListComp -XParallelListComp 
Prelude> [(x :: [Int]) | x <- [1,2,1,2], then group by x ] :: [[Int]]

<interactive>:2:49: error: parse error on input ‘]’
Prelude>

Expected behavior

Documentation says

[(x :: [Int]) | x <- [1,2,1,2], then group by x ] :: [[Int]]

-- translates to:
do x <- mgroupWith (\x -> x) [1,2,1,2]
   return x

but I can't find mgroupWith.

But this works

Prelude GHC.Exts> [ x | x <- [1,2,1,2], then group by x using GHC.Exts.groupWith]
[[1,1],[2,2]]
Prelude GHC.Exts> GHC.Exts.groupWith id [1,2,1,2]
[[1,1],[2,2]]

So change the documentation?

Environment

  • GHC version used: GHCi 8.10.2

Optional:

  • Operating System: Arch Linux
  • System Architecture: 64-bit PC
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information