) where
import Prelude hiding (id,(.))
-import qualified Prelude
import Control.Monad
import Control.Monad.Fix
infixr 1 ^<<, <<^
-- | The basic arrow class.
--- Any instance must define either 'arr' or 'pure' (which are synonyms),
--- as well as 'first'. The other combinators have sensible
--- default definitions, which may be overridden for efficiency.
+--
+-- Minimal complete definition: 'arr' and 'first'.
+--
+-- The other combinators have sensible default definitions,
+-- which may be overridden for efficiency.
class Category a => Arrow a where
- -- | Lift a function to an arrow: you must define either this
- -- or 'pure'.
+ -- | Lift a function to an arrow.
arr :: (b -> c) -> a b c
- arr = pure
-
- -- | A synonym for 'arr': you must define one or other of them.
- pure :: (b -> c) -> a b c
- pure = arr
-- | Send the first component of the input through the argument
-- arrow, and copy the rest unchanged to the output.
-- version if desired.
second :: a b c -> a (d,b) (d,c)
second f = arr swap >>> first f >>> arr swap
- where swap ~(x,y) = (y,x)
+ where swap :: (x,y) -> (y,x)
+ swap ~(x,y) = (y,x)
-- | Split the input between the two argument arrows and combine
-- their output. Note that this is in general not a functor.
f &&& g = arr (\b -> (b,b)) >>> f *** g
{-# RULES
-"identity"
- arr id = id
"compose/arr" forall f g .
(arr f) . (arr g) = arr (f . g)
"first/arr" forall f .
-- version if desired.
right :: a b c -> a (Either d b) (Either d c)
right f = arr mirror >>> left f >>> arr mirror
- where mirror (Left x) = Right x
+ where mirror :: Either x y -> Either y x
+ mirror (Left x) = Right x
mirror (Right y) = Left y
-- | Split the input between the two argument arrows, retagging
"fanin/arr" forall f g .
arr f ||| arr g = arr (f ||| g)
"compose/left" forall f g .
- left f >>> left g = left (f >>> g)
+ left f . left g = left (f . g)
"compose/right" forall f g .
- right f >>> right g = right (f >>> g)
+ right f . right g = right (f . g)
#-}
instance ArrowChoice (->) where