Added Applicative and Alternative instances for STM
[ghc-base.git] / Control / Arrow.hs
index ebc8249..f3c1de2 100644 (file)
@@ -4,7 +4,7 @@
 -- Copyright   :  (c) Ross Paterson 2002
 -- License     :  BSD-style (see the LICENSE file in the distribution)
 --
--- Maintainer  :  ross@soi.city.ac.uk
+-- Maintainer  :  libraries@haskell.org
 -- Stability   :  experimental
 -- Portability :  portable
 --
@@ -33,11 +33,12 @@ module Control.Arrow (
                 -- * Arrow application
                 ArrowApply(..), ArrowMonad(..), leftApp,
                 -- * Feedback
-                ArrowLoop(..)
+                ArrowLoop(..),
+
+                (>>>), (<<<) -- reexported
         ) where
 
 import Prelude hiding (id,(.))
-import qualified Prelude
 
 import Control.Monad
 import Control.Monad.Fix
@@ -52,20 +53,16 @@ infixr 1 ^>>, >>^
 infixr 1 ^<<, <<^
 
 -- | The basic arrow class.
---   Any instance must define either 'arr' or 'pure' (which are synonyms),
---   as well as 'first'.  The other combinators have sensible
---   default definitions, which may be overridden for efficiency.
+--
+--   Minimal complete definition: 'arr' and 'first'.
+--
+--   The other combinators have sensible default definitions,
+--   which may be overridden for efficiency.
 
 class Category a => Arrow a where
 
-        -- | Lift a function to an arrow: you must define either this
-        --   or 'pure'.
+        -- | Lift a function to an arrow.
         arr :: (b -> c) -> a b c
-        arr = pure
-
-        -- | A synonym for 'arr': you must define one or other of them.
-        pure :: (b -> c) -> a b c
-        pure = arr
 
         -- | Send the first component of the input through the argument
         --   arrow, and copy the rest unchanged to the output.
@@ -96,8 +93,6 @@ class Category a => Arrow a where
         f &&& g = arr (\b -> (b,b)) >>> f *** g
 
 {-# RULES
-"identity"
-                arr id = id
 "compose/arr"   forall f g .
                 (arr f) . (arr g) = arr (f . g)
 "first/arr"     forall f .
@@ -162,7 +157,7 @@ class Arrow a => ArrowZero a where
         zeroArrow :: a b c
 
 instance MonadPlus m => ArrowZero (Kleisli m) where
-        zeroArrow = Kleisli (\x -> mzero)
+        zeroArrow = Kleisli (\_ -> mzero)
 
 class ArrowZero a => ArrowPlus a where
         (<+>) :: a b c -> a b c -> a b c
@@ -219,9 +214,9 @@ class Arrow a => ArrowChoice a where
 "fanin/arr"     forall f g .
                 arr f ||| arr g = arr (f ||| g)
 "compose/left"  forall f g .
-                left f >>> left g = left (f >>> g)
+                left f . left g = left (f . g)
 "compose/right" forall f g .
-                right f >>> right g = right (f >>> g)
+                right f . right g = right (f . g)
  #-}
 
 instance ArrowChoice (->) where
@@ -253,7 +248,7 @@ instance Monad m => ArrowApply (Kleisli m) where
 newtype ArrowApply a => ArrowMonad a b = ArrowMonad (a () b)
 
 instance ArrowApply a => Monad (ArrowMonad a) where
-        return x = ArrowMonad (arr (\z -> x))
+        return x = ArrowMonad (arr (\_ -> x))
         ArrowMonad m >>= f = ArrowMonad (m >>>
                         arr (\x -> let ArrowMonad h = f x in (h, ())) >>>
                         app)