X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FArrow.hs;h=2710be6e9c469e3b05da06b1013ad64e4eac610b;hb=afe7ed8026edd943550b05f4895c99601207fea5;hp=316ef06de06c1650ecc75a16b2d0bb70173d15dd;hpb=7de614790f72f6a8ebe81ea8ec4ee173e81f406d;p=haskell-directory.git diff --git a/Control/Arrow.hs b/Control/Arrow.hs index 316ef06..2710be6 100644 --- a/Control/Arrow.hs +++ b/Control/Arrow.hs @@ -22,7 +22,10 @@ module Control.Arrow ( -- * Arrows Arrow(..), Kleisli(..), -- ** Derived combinators - returnA, (<<<), + returnA, + (^>>), (>>^), + -- ** Right-to-left variants + (<<<), (<<^), (^<<), -- * Monoid operations ArrowZero(..), ArrowPlus(..), -- * Conditionals @@ -43,8 +46,8 @@ infixr 3 *** infixr 3 &&& infixr 2 +++ infixr 2 ||| -infixr 1 >>> -infixr 1 <<< +infixr 1 >>>, ^>>, >>^ +infixr 1 <<<, ^<<, <<^ -- | The basic arrow class. -- Any instance must define either 'arr' or 'pure' (which are synonyms), @@ -123,7 +126,7 @@ instance Arrow (->) where -- | Kleisli arrows of a monad. -newtype Kleisli m a b = Kleisli (a -> m b) +newtype Kleisli m a b = Kleisli { runKleisli :: a -> m b } instance Monad m => Arrow (Kleisli m) where arr f = Kleisli (return . f) @@ -136,11 +139,26 @@ instance Monad m => Arrow (Kleisli m) where returnA :: Arrow a => a b b returnA = arr id --- | Right-to-left composition, for a better fit with arrow notation. +-- | Precomposition with a pure function. +(^>>) :: Arrow a => (b -> c) -> a c d -> a b d +f ^>> a = arr f >>> a + +-- | Postcomposition with a pure function. +(>>^) :: Arrow a => a b c -> (c -> d) -> a b d +a >>^ f = a >>> arr f +-- | Right-to-left composition, for a better fit with arrow notation. (<<<) :: Arrow a => a c d -> a b c -> a b d f <<< g = g >>> f +-- | Precomposition with a pure function (right-to-left variant). +(<<^) :: Arrow a => a c d -> (b -> c) -> a b d +a <<^ f = a <<< arr f + +-- | Postcomposition with a pure function (right-to-left variant). +(^<<) :: Arrow a => (c -> d) -> a b c -> a b d +f ^<< a = arr f <<< a + class Arrow a => ArrowZero a where zeroArrow :: a b c