1{-# LANGUAGE TypeFamilies, ConstraintKinds, MultiParamTypeClasses
2  #-}
3module Control.RCategory where
4import qualified Prelude
5import GHC.Prim
6
7infixr 9 .
8
9infixr 1 >>>, <<<
10
11class RCategory cat where
12        type RCategoryCtxt cat a b :: Constraint
13
14        id :: RCategoryCtxt cat a a => cat a a
15
16        (.) ::
17              (RCategoryCtxt cat b c, RCategoryCtxt cat a b,
18               RCategoryCtxt cat a c) =>
19              cat b c -> cat a b -> cat a c
20
21{-# RULES
22"identity/left" forall p . id . p = p
23"identity/right" forall p . p . id = p
24 #-}
25
26instance RCategory (->) where
27        type RCategoryCtxt (->) a a = ()
28        id = Prelude.id
29        (.) = (Prelude..)
30
31(<<<) ::
32        (RCategoryCtxt cat a c, RCategoryCtxt cat a b,
33         RCategoryCtxt cat b c, RCategory cat) =>
34        cat b c -> cat a b -> cat a c
35(<<<) = (.)
36
37(>>>) ::
38        (RCategoryCtxt cat a c, RCategoryCtxt cat a b,
39         RCategoryCtxt cat b c, RCategory cat) =>
40        cat a b -> cat b c -> cat a c
41f >>> g = g . f
42