1 {-# LANGUAGE RankNTypes, MultiParamTypeClasses, NoMonomorphismRestriction, TypeOperators, FunctionalDependencies, TypeFamilies, FlexibleContexts, FlexibleInstances, DatatypeContexts #-}
2 -----------------------------------------------------------------------------
4 -- Module : GHC.HetMet.IGArrow
6 -- License : public domain
8 -- Maintainer : Adam Megacz <megacz@acm.org>
9 -- Stability : experimental
10 -- Portability : portable
12 module GHC.HetMet.IGArrow (
26 -- IGArrowSum(..), ga_inl, ga_inr,
30 import Control.Category hiding ((.))
31 import GHC.HetMet.GArrow
32 import Prelude hiding (id)
33 import GHC.HetMet.Arrow
39 ------------------------------------------------------------------------
42 -- | An "internal generalized arrow" is a GArrow except that it uses
43 -- some *other* GArrow in place of Haskell's function space.
45 class IGArrow g (**) u gg (***) uu where
46 iga_id :: g u (gg x x)
47 iga_comp :: g ((gg x y) ** (gg y z)) (gg x z)
48 iga_first :: g (gg x y) (gg (x *** z) (y *** z))
49 iga_second :: g (gg x y) (gg (z *** x) (z *** y))
50 iga_cancell :: g u (gg (uu***x) x)
51 iga_cancelr :: g u (gg (x***uu) x)
52 iga_uncancell :: g u (gg x (uu***x))
53 iga_uncancelr :: g u (gg x (x***uu))
54 iga_assoc :: g u (gg ((x*** y)***z ) ( x***(y ***z)))
55 iga_unassoc :: g u (gg ( x***(y ***z)) ((x*** y)***z ))
57 class IGArrow g (**) u gg (***) uu => IGArrowCopy g (**) u gg (***) uu where
58 iga_copy :: g u (gg x (x***x))
60 class IGArrow g (**) u gg (***) uu => IGArrowDrop g (**) u gg (***) uu where
61 iga_drop :: g u (gg x u)
63 class IGArrow g (**) u gg (***) uu => IGArrowSwap g (**) u gg (***) uu where
64 iga_swap :: g u (gg (x***y) (y***x))
66 class IGArrow g (**) u gg (***) uu => IGArrowLoop g (**) u gg (***) uu where
67 iga_loopr :: g (gg (x***z) (y***z)) (gg x y)
68 iga_loopl :: g (gg (z***x) (z***y)) (gg x y)
70 class IGArrow g (**) u gg (***) uu => IGArrowLiteral g (**) u gg (***) uu t r where
71 iga_literal :: g t (gg uu r)
73 class IGArrow g (**) u gg (***) uu => IGArrowEval g (**) u gg (***) uu r t where
74 iga_eval :: g (gg uu r) t
76 class IGArrow g (**) u gg (***) uu => IGArrowConstant g (**) u gg (***) uu t r where
77 iga_constant :: g t (gg uu r)
79 class IGArrow g (**) u gg (***) uu => IGArrowReify g (**) u gg (***) uu x y r q where
80 iga_reify :: g (g x y) (gg r q)
82 class IGArrow g (**) u gg (***) uu => IGArrowReflect g (**) u gg (***) uu r q x y where
83 iga_reflect :: g (gg r q) (g x y)
89 ------------------------------------------------------------------------------
90 -- Self-Internal GArrows
93 -- | A self-internal GArrow is, well, internal to itself
95 class IGArrow g (**) u g (**) u => SelfInternalGArrow g (**) u
98 -- | Self-internal GArrows have curry/apply
100 -- instance SelfInternalGArrow g (**) u => GArrowApply g (**) u gg where
101 -- ga_applyl = :: g (x**(g x y) ) y
102 -- ga_applyr :: g ( (g x y)**x) y
105 -- | Self-internal GArrows have curry/apply
107 -- instance SelfInternalGArrow g (**) u gg (***) uu => GArrowCurry g (**) u gg where
108 -- ga_curryl :: g (x**y) z -> g x (g y z)
109 -- ga_curryr :: g (x**y) z -> g y (g x z)
115 ------------------------------------------------------------------------------
119 -- | Every GArrow is internal to the GArrow instance on (->)
121 instance GArrow g (**) u => IGArrow (->) (,) () g (**) u where
123 iga_comp (f,g) = f >>> g
125 iga_second = ga_second
126 iga_cancell _ = ga_cancell
127 iga_cancelr _ = ga_cancelr
128 iga_uncancell _ = ga_uncancell
129 iga_uncancelr _ = ga_uncancelr
130 iga_assoc _ = ga_assoc
131 iga_unassoc _ = ga_unassoc
138 ------------------------------------------------------------------------
141 -- | An IGArrow may be "externalized" to form a normal generalized
142 -- arrow. If the IGArrow was an instance of class IGArrowXX, the
143 -- externalization will be an instance of GArrowYY.
145 -- TODO: I should be one level deeper here: assuming an (IGArrow
146 -- (IGArrow g)), create an (IGArrow g).
150 IGArrow g (**) u q (***) uu =>
151 Ext g (**) u q (***) uu x y
152 = Ext { unExt :: g u (q x y) }
154 -- instance IGArrow g (**) u gg (***) uu => GArrowCopy g (**) u gg (***) uu where
155 -- iga_copy = undefined
157 -- instance IGArrow g (**) u gg (***) uu => GArrowDrop g (**) u gg (***) uu where
158 -- iga_drop = undefined
160 -- instance IGArrow g (**) u gg (***) uu => GArrowSwap g (**) u gg (***) uu where
161 -- iga_swap = undefined
163 -- instance IGArrow g (**) u gg (***) uu => GArrowLoop g (**) u gg (***) uu where
164 -- iga_loopr = undefined
165 -- iga_loopl = undefined
167 -- instance IGArrow g (**) u gg (***) uu => GArrowLiteral g (**) u gg (***) uu t r where
168 -- iga_literal = undefined
170 -- instance IGArrow g (**) u gg (***) uu => GArrowEval g (**) u gg (***) uu r t where
171 -- iga_eval = undefined
173 -- instance IGArrow g (**) u gg (***) uu => GArrowConstant g (**) u gg (***) uu t r where
174 -- iga_constant = undefined
176 -- instance IGArrow g (**) u gg (***) uu => GArrowReify g (**) u gg (***) uu x y r q where
177 -- iga_reify = undefined
179 -- instance IGArrow g (**) u gg (***) uu => GArrowReflect g (**) u gg (***) uu r q x y where
180 -- iga_reflect = undefined