add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / Control / Category.hs
1 {-# LANGUAGE CPP #-}
2
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module      :  Control.Category
6 -- Copyright   :  (c) Ashley Yakeley 2007
7 -- License     :  BSD-style (see the LICENSE file in the distribution)
8 --
9 -- Maintainer  :  ashley@semantic.org
10 -- Stability   :  experimental
11 -- Portability :  portable
12
13 -- http://hackage.haskell.org/trac/ghc/ticket/1773
14
15 module Control.Category where
16
17 import qualified Prelude
18
19 infixr 9 .
20 infixr 1 >>>, <<<
21
22 -- | A class for categories.
23 --   id and (.) must form a monoid.
24 class Category cat where
25     -- | the identity morphism
26     id :: cat a a
27
28     -- | morphism composition
29     (.) :: cat b c -> cat a b -> cat a c
30
31 {-# RULES
32 "identity/left" forall p .
33                 id . p = p
34 "identity/right"        forall p .
35                 p . id = p
36 "association"   forall p q r .
37                 (p . q) . r = p . (q . r)
38  #-}
39
40 instance Category (->) where
41     id = Prelude.id
42 #ifndef __HADDOCK__
43 -- Haddock 1.x cannot parse this:
44     (.) = (Prelude..)
45 #endif
46
47 -- | Right-to-left composition
48 (<<<) :: Category cat => cat b c -> cat a b -> cat a c
49 (<<<) = (.)
50
51 -- | Left-to-right composition
52 (>>>) :: Category cat => cat a b -> cat b c -> cat a c
53 f >>> g = g . f