monad comprehensions: Group and Zip monad
[ghc-base.git] / Control / Monad / Group.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module      :  Control.Monad.Group
4 -- Copyright   :  (c) Nils Schweinsberg 2011,
5 --                (c) University Tuebingen 2011
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer  :  libraries@haskell.org
8 -- Stability   :  experimental
9 -- Portability :  non-portable
10 --
11 -- Monadic grouping (used for monad comprehensions)
12 --
13 -----------------------------------------------------------------------------
14
15 {-# LANGUAGE CPP, MultiParamTypeClasses, FlexibleInstances #-}
16
17 module Control.Monad.Group where
18
19 import Prelude
20 #if defined(__GLASGOW_HASKELL__)
21 import GHC.Exts (groupWith)
22 #endif
23
24 -- | `MonadGroup` type class without restrictions on the type `t`
25 class Monad m => MonadGroup m t where
26     mgroupWith :: (a -> t) -> m a -> m (m a)
27
28 #if defined(__GLASGOW_HASKELL__)
29 -- | Grouping instance for lists using the `groupWith` function from the
30 -- "GHC.Exts" library
31 instance Ord t => MonadGroup [] t where
32     mgroupWith = groupWith
33 #endif