monad comprehensions: Group and Zip monad
[ghc-base.git] / Control / Monad / Group.hs
diff --git a/Control/Monad/Group.hs b/Control/Monad/Group.hs
new file mode 100644 (file)
index 0000000..baab7da
--- /dev/null
@@ -0,0 +1,33 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Monad.Group
+-- Copyright   :  (c) Nils Schweinsberg 2011,
+--                (c) University Tuebingen 2011
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
+-- Maintainer  :  libraries@haskell.org
+-- Stability   :  experimental
+-- Portability :  non-portable
+--
+-- Monadic grouping (used for monad comprehensions)
+--
+-----------------------------------------------------------------------------
+
+{-# LANGUAGE CPP, MultiParamTypeClasses, FlexibleInstances #-}
+
+module Control.Monad.Group where
+
+import Prelude
+#if defined(__GLASGOW_HASKELL__)
+import GHC.Exts (groupWith)
+#endif
+
+-- | `MonadGroup` type class without restrictions on the type `t`
+class Monad m => MonadGroup m t where
+    mgroupWith :: (a -> t) -> m a -> m (m a)
+
+#if defined(__GLASGOW_HASKELL__)
+-- | Grouping instance for lists using the `groupWith` function from the
+-- "GHC.Exts" library
+instance Ord t => MonadGroup [] t where
+    mgroupWith = groupWith
+#endif