X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=GHC%2FHetMet%2FGArrow.hs;h=9853637c0a00752e32ca367c4bef110b60490237;hb=8a1129a742003ddacb0fa331309434b5e2953cd8;hp=da6a9c2bde822e59ccb6ff17c22c3e606a28f777;hpb=28aab94598bf79fd5dc005d71934555f330b0ad7;p=ghc-base.git diff --git a/GHC/HetMet/GArrow.hs b/GHC/HetMet/GArrow.hs index da6a9c2..9853637 100644 --- a/GHC/HetMet/GArrow.hs +++ b/GHC/HetMet/GArrow.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -XRankNTypes -XMultiParamTypeClasses -XNoMonomorphismRestriction -XTypeOperators -XFlexibleInstances #-} +{-# OPTIONS -XRankNTypes -XMultiParamTypeClasses -XNoMonomorphismRestriction -XTypeOperators -XFlexibleInstances -XFunctionalDependencies #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.HetMet.GArrow @@ -19,10 +19,9 @@ module GHC.HetMet.GArrow ( GArrowReflect(..) ) where import Control.Arrow +import Control.Category -class GArrow g (**) where - ga_id :: g x x - ga_comp :: g x y -> g y z -> g x z +class Category g => GArrow g (**) | g -> (**) where 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 @@ -42,7 +41,7 @@ class GArrow g (**) => GArrowSwap g (**) where ga_swap :: g (x**y) (y**x) -- implementation of ga_second for GArrowSwap instances -ga_swap_second f = ga_comp (ga_comp ga_swap (ga_first f)) ga_swap +ga_swap_second f = ga_swap >>> ga_first f >>> ga_swap class GArrow g (**) => GArrowLoop g (**) where ga_loop :: g (x**z) (y**z) -> g x y @@ -60,3 +59,37 @@ class GArrow g (**) => GArrowReflect g (**) where +------------------------------------------------------------------------------ +-- GArrow instances for Control.Arrow + +instance Arrow a => GArrow a (,) where + ga_first = first + ga_second = second + ga_cancell = arr (\((),x) -> x) + ga_cancelr = arr (\(x,()) -> x) + ga_uncancell = arr (\x -> ((),x)) + ga_uncancelr = arr (\x -> (x,())) + ga_assoc = arr (\((x,y),z) -> (x,(y,z))) + ga_unassoc = arr (\(x,(y,z)) -> ((x,y),z)) + +instance Arrow a => GArrowDrop a (,) where + ga_drop = arr (\x -> ()) + +instance Arrow a => GArrowCopy a (,) where + ga_copy = arr (\x -> (x,x)) + +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 => GArrowReify a (,) where + ga_reify = arr + +instance ArrowLoop a => GArrowLoop a (,) where + ga_loop = loop + + + +