optional, some, many
) where
-#ifdef __HADDOCK__
-import Prelude
-#endif
+import Prelude hiding (id,(.))
-import Control.Compositor
+import Control.Category
import Control.Arrow
(Arrow(arr, (&&&)), ArrowZero(zeroArrow), ArrowPlus((<+>)))
import Control.Monad (liftM, ap, MonadPlus(..))
ArrowLoop(..)
) where
-import Prelude
+import Prelude hiding (id,(.))
import Control.Monad
import Control.Monad.Fix
-import Control.Compositor
+import Control.Category
infixr 5 <+>
infixr 3 ***
-- as well as 'first'. The other combinators have sensible
-- default definitions, which may be overridden for efficiency.
-class Compositor a => Arrow a where
+class Category a => Arrow a where
-- | Lift a function to an arrow: you must define either this
-- or 'pure'.
{-# RULES
"identity"
- arr id = identity
+ arr id = id
"compose/arr" forall f g .
- arr f >>> arr g = arr (f >>> g)
+ (arr f) . (arr g) = arr (f . g)
"first/arr" forall f .
first (arr f) = arr (first f)
"second/arr" forall f .
"fanout/arr" forall f g .
arr f &&& arr g = arr (f &&& g)
"compose/first" forall f g .
- first f >>> first g = first (f >>> g)
+ (first f) . (first g) = first (f . g)
"compose/second" forall f g .
- second f >>> second g = second (f >>> g)
+ (second f) . (second g) = second (f . g)
#-}
-- Ordinary functions are arrows.
newtype Kleisli m a b = Kleisli { runKleisli :: a -> m b }
-instance Monad m => Compositor (Kleisli m) where
- identity = Kleisli return
- Kleisli f >>> Kleisli g = Kleisli (\b -> f b >>= g)
+instance Monad m => Category (Kleisli m) where
+ id = Kleisli return
+ (Kleisli f) . (Kleisli g) = Kleisli (\b -> g b >>= f)
instance Monad m => Arrow (Kleisli m) where
arr f = Kleisli (return . f)
--- /dev/null
+-----------------------------------------------------------------------------
+-- |
+-- Module : Control.Category
+-- Copyright : (c) Ashley Yakeley 2007
+-- License : BSD-style (see the LICENSE file in the distribution)
+--
+-- Maintainer : ashley@semantic.org
+-- Stability : experimental
+-- Portability : portable
+
+-- http://hackage.haskell.org/trac/ghc/ticket/1773
+
+module Control.Category where
+
+import Prelude hiding (id,(.))
+import qualified Prelude
+
+infixr 9 .
+infixr 1 >>>, <<<
+
+-- | A class for categories.
+-- id and (.) must form a monoid.
+class Category cat where
+ -- | the identity morphism
+ id :: cat a a
+
+ -- | morphism composition
+ (.) :: cat b c -> cat a b -> cat a c
+
+{-# RULES
+"identity/left" forall p .
+ id . p = p
+"identity/right" forall p .
+ p . id = p
+"association" forall p q r .
+ (p . q) . r = p . (q . r)
+ #-}
+
+instance Category (->) where
+ id = Prelude.id
+ (.) = (Prelude..)
+
+-- | Right-to-left composition
+(<<<) :: Category cat => cat b c -> cat a b -> cat a c
+(<<<) = (.)
+
+-- | Left-to-right composition
+(>>>) :: Category cat => cat a b -> cat b c -> cat a c
+f >>> g = g . f
+++ /dev/null
------------------------------------------------------------------------------
--- |
--- Module : Control.Compositor
--- Copyright : (c) Ashley Yakeley 2007
--- License : BSD-style (see the LICENSE file in the distribution)
---
--- Maintainer : ashley@semantic.org
--- Stability : experimental
--- Portability : portable
-
-module Control.Compositor where
-
-infixr 1 >>>, <<<
-
-class Compositor comp where
- identity :: comp a a
-
- -- | Left-to-right composition
- (>>>) :: comp a b -> comp b c -> comp a c
-
-{-# RULES
-"identity/left" forall p .
- identity >>> p = p
-"identity/right" forall p .
- p >>> identity = p
-"association" forall p q r .
- (p >>> q) >>> r = p >>> (q >>> r)
- #-}
-
-instance Compositor (->) where
- identity = id
- p >>> q = q . p
-
--- | Right-to-left composition
-(<<<) :: Compositor comp => comp b c -> comp a b -> comp a c
-f <<< g = g >>> f
-
exposed-modules:
Control.Applicative,
Control.Arrow,
- Control.Compositor,
+ Control.Category,
Control.Concurrent,
Control.Concurrent.Chan,
Control.Concurrent.MVar,