instance Arrow a => GArrowSwap a (,) where
ga_swap = arr (\(x,y) -> (y,x))
-instance Arrow a => GArrowLiteral a (,) b where
- ga_literal x = arr (\() -> x)
+instance Arrow a => GArrowConstant a (,) where
+ ga_constant x = arr (\() -> x)
instance Arrow a => GArrowReify a (,) where
ga_reify = arr
GArrowCopy(..),
GArrowSwap(..),
GArrowLoop(..),
+ GArrowConstant(..),
+ GArrowRun(..),
GArrowReify(..),
- GArrowReflect(..),
- GArrowLiteral(..)
+ GArrowReflect(..)
) where
import Control.Category
+------------------------------------------------------------------------
+-- The main GArrow class
+
class Category g => GArrow g (**) | g -> (**) where
+--id :: g x x
+--comp :: g x y -> g y z -> g x z
ga_first :: g x y -> g (x ** z) (y ** z)
ga_second :: g x y -> g (z ** x) (z ** y)
ga_cancell :: g (()**x) x
ga_assoc :: g ((x**y)**z) (x**(y**z))
ga_unassoc :: g (x**(y**z)) ((x**y)**z)
-class GArrow g (**) => GArrowDrop g (**) where
- ga_drop :: g x ()
+
+------------------------------------------------------------------------
+-- The three context-manipulation classes
class GArrow g (**) => GArrowCopy g (**) where
ga_copy :: g x (x**x)
+class GArrow g (**) => GArrowDrop g (**) where
+ ga_drop :: g x ()
+
class GArrow g (**) => GArrowSwap g (**) where
- ga_swap :: g (x**y) (y**x)
+ ga_swap :: g (x**y) (y**x)
+
+ga_swap_second f =
+ ga_swap >>> ga_first f >>> ga_swap
+ -- implementation of ga_second for GArrowSwap
+ -- See also
+ -- http://haskell.org/haskellwiki/Class_system_extension_proposal
+ -- "Allowing superclass methods to be overridden in derived classes";
+ -- if we had this we could do a better job here
+
+
--- implementation of ga_second for GArrowSwap instances
-ga_swap_second f = ga_swap >>> ga_first f >>> ga_swap
+------------------------------------------------------------------------
+-- Loop
class GArrow g (**) => GArrowLoop g (**) where
ga_loop :: g (x**z) (y**z) -> g x y
-class GArrow g (**) => GArrowLiteral g (**) a where
- ga_literal :: a -> g () a
--- not sure -- subject to change
+
+------------------------------------------------------------------------
+-- Constant and Run, which are dual to each other
+
+class GArrow g (**) => GArrowConstant g (**) where
+ ga_constant :: a -> g () a
+
+-- the dual of GArrowConstant
+class GArrow g (**) => GArrowRun g (**) where
+ ga_run :: g () a -> a
+
+
+
+------------------------------------------------------------------------
+-- Reify and Reflect, which are "curried" versions
+
+-- Not sure -- subject to change. If you have this, you're basically
+-- a Control.Arrow; you can also define essentially all the other
+-- methods of GArrow, GArrowDrop, GArrowCopy, etc in terms of this.
class GArrow g (**) => GArrowReify g (**) where
ga_reify :: (x -> y) -> g x y
-- not sure -- subject to change
class GArrow g (**) => GArrowReflect g (**) where
ga_reflect :: g x y -> (x -> y)
-