arrows 0.3 → 0.4
raw patch · 9 files changed
+173/−15 lines, 9 files
Files
- Control/Arrow/Transformer/Automaton.hs +22/−2
- Control/Arrow/Transformer/CoState.hs +21/−1
- Control/Arrow/Transformer/Error.hs +20/−1
- Control/Arrow/Transformer/Reader.hs +21/−1
- Control/Arrow/Transformer/State.hs +21/−1
- Control/Arrow/Transformer/Static.hs +21/−2
- Control/Arrow/Transformer/Stream.hs +23/−3
- Control/Arrow/Transformer/Writer.hs +20/−1
- arrows.cabal +4/−3
Control/Arrow/Transformer/Automaton.hs view
@@ -13,13 +13,16 @@ -- Simple Mealy-style automata. module Control.Arrow.Transformer.Automaton(- Automaton, runAutomaton,+ Automaton(Automaton), runAutomaton, ) where -import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer++import Control.Applicative+import Control.Arrow hiding (pure)+import Data.Monoid import Data.Stream -- | An arrow type comprising Mealy-style automata, each step of which is@@ -62,6 +65,23 @@ instance ArrowLoop a => ArrowCircuit (Automaton a) where delay x = Automaton (arr (\x' -> (x, delay x')))++-- Other instances++instance Arrow a => Functor (Automaton a b) where+ fmap f g = g >>> arr f++instance Arrow a => Applicative (Automaton a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance ArrowPlus a => Alternative (Automaton a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance ArrowPlus a => Monoid (Automaton a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- runAutomaton (Automaton f) = proc (e, Cons x xs) -> do -- (y, c) <- f <- (e, x)
Control/Arrow/Transformer/CoState.hs view
@@ -18,9 +18,12 @@ CoStateArrow, ) where -import Control.Arrow import Control.Arrow.Operations +import Control.Applicative+import Control.Arrow hiding (pure)+import Data.Monoid+ newtype CoStateArrow s a b c = CST (a (s -> b) (s -> c)) instance Arrow a => Arrow (CoStateArrow s a) where@@ -46,3 +49,20 @@ instance ArrowPlus a => ArrowPlus (CoStateArrow s a) where CST f <+> CST g = CST (f <+> g)++-- Other instances++instance Arrow a => Functor (CoStateArrow s a b) where+ fmap f g = g >>> arr f++instance Arrow a => Applicative (CoStateArrow s a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance ArrowPlus a => Alternative (CoStateArrow s a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance ArrowPlus a => Monoid (CoStateArrow s a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g
Control/Arrow/Transformer/Error.hs view
@@ -20,10 +20,12 @@ ArrowAddError(..), ) where -import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer++import Control.Applicative+import Control.Arrow hiding (pure) import Data.Monoid -- | An arrow that augments an existing arrow with possible errors.@@ -87,6 +89,23 @@ fstRight (Right (x,_)) = Right x fromRight (Left _) = error "fromRight" fromRight (Right y) = y++-- Other instances++instance ArrowChoice a => Functor (ErrorArrow ex a b) where+ fmap f g = g >>> arr f++instance ArrowChoice a => Applicative (ErrorArrow ex a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance (Monoid ex, ArrowChoice a) => Alternative (ErrorArrow ex a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance (Monoid ex, ArrowChoice a) => Monoid (ErrorArrow ex a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- fresh instances
Control/Arrow/Transformer/Reader.hs view
@@ -18,11 +18,14 @@ ArrowAddReader(..), ) where -import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer +import Control.Applicative+import Control.Arrow hiding (pure)+import Data.Monoid+ -- | An arrow type that augments an existing arrow with a read-only state -- (or environment). The 'ArrowReader' class contains the operations -- on this state.@@ -127,3 +130,20 @@ ArrowAddWriter s (ReaderArrow r a) (ReaderArrow r a') where liftWriter (ReaderArrow f) = ReaderArrow (liftWriter f) elimWriter (ReaderArrow f) = ReaderArrow (elimWriter f)++-- Other instances++instance Arrow a => Functor (ReaderArrow r a b) where+ fmap f g = g >>> arr f++instance Arrow a => Applicative (ReaderArrow r a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance ArrowPlus a => Alternative (ReaderArrow r a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance ArrowPlus a => Monoid (ReaderArrow r a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g
Control/Arrow/Transformer/State.hs view
@@ -20,11 +20,14 @@ ArrowAddState(..), ) where -import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer +import Control.Applicative+import Control.Arrow hiding (pure)+import Data.Monoid+ -- | An arrow type that augments an existing arrow with a modifiable -- state. The 'ArrowState' class contains the operations on this state. newtype StateArrow s a b c = ST (a (b, s) (c, s))@@ -107,6 +110,23 @@ instance ArrowPlus a => ArrowPlus (StateArrow s a) where ST f <+> ST g = ST (f <+> g)++-- Other instances++instance Arrow a => Functor (StateArrow s a b) where+ fmap f g = g >>> arr f++instance Arrow a => Applicative (StateArrow s a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance ArrowPlus a => Alternative (StateArrow s a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance ArrowPlus a => Monoid (StateArrow s a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- promotions
Control/Arrow/Transformer/Static.hs view
@@ -17,12 +17,14 @@ wrapA, unwrapA, wrapM, unwrapM, ) where -import Control.Applicative-import Control.Arrow hiding (pure) import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer++import Control.Applicative+import Control.Arrow hiding (pure) import Control.Monad+import Data.Monoid -- | An arrow type that augments the underlying arrow with static information. @@ -73,6 +75,23 @@ instance (ArrowPlus a, Applicative f) => ArrowPlus (StaticArrow f a) where SA f <+> SA g = SA ((<+>) <$> f <*> g)++-- Other instances++instance (Arrow a, Applicative f) => Functor (StaticArrow f a b) where+ fmap f g = g >>> arr f++instance (Arrow a, Applicative f) => Applicative (StaticArrow f a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance (ArrowPlus a, Applicative f) => Alternative (StaticArrow f a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance (ArrowPlus a, Applicative f) => Monoid (StaticArrow f a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- promotions
Control/Arrow/Transformer/Stream.hs view
@@ -20,15 +20,18 @@ ArrowAddStream(..), ) where -import Control.Monad.ST--import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer+ import Data.Stream (Stream(..)) import qualified Data.Stream as Stream +import Control.Applicative+import Control.Arrow hiding (pure)+import Control.Monad.ST+import Data.Monoid+ -- | Arrows between streams. -- -- /Note/: 'lift' is only a functor if '***' in the underlying arrow is.@@ -93,6 +96,23 @@ instance ArrowLoop a => ArrowCircuit (StreamArrow a) where delay x = Str (arr (Cons x))++-- Other instances++instance Arrow a => Functor (StreamArrow a b) where+ fmap f g = g >>> arr f++instance Arrow a => Applicative (StreamArrow a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance ArrowPlus a => Alternative (StreamArrow a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance ArrowPlus a => Monoid (StreamArrow a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- | Run a stream processor on a stream of inputs, obtaining a stream -- of outputs.
Control/Arrow/Transformer/Writer.hs view
@@ -18,10 +18,12 @@ ArrowAddWriter(..), ) where -import Control.Arrow import Control.Arrow.Internals import Control.Arrow.Operations import Control.Arrow.Transformer++import Control.Applicative+import Control.Arrow hiding (pure) import Data.Monoid -- | An arrow type that augments an existing arrow with accumulating@@ -79,6 +81,23 @@ instance (ArrowLoop a, Monoid w) => ArrowLoop (WriterArrow w a) where loop (WriterArrow f) = WriterArrow (loop (f >>> arr swapenv)) where swapenv ~(~(x, y), w) = ((x, w), y)++-- Other instances++instance (Arrow a, Monoid w) => Functor (WriterArrow w a b) where+ fmap f g = g >>> arr f++instance (Arrow a, Monoid w) => Applicative (WriterArrow w a b) where+ pure x = arr (const x)+ f <*> g = f &&& g >>> arr (uncurry id)++instance (ArrowPlus a, Monoid w) => Alternative (WriterArrow w a b) where+ empty = zeroArrow+ f <|> g = f <+> g++instance (ArrowPlus a, Monoid w) => Monoid (WriterArrow w a b c) where+ mempty = zeroArrow+ mappend f g = f <+> g -- new instances
arrows.cabal view
@@ -1,12 +1,13 @@ Name: arrows-Version: 0.3-Build-Depends: base >= 2.0, Stream+Version: 0.4+Build-Depends: base >= 2.0 && < 3.1, Stream Build-Type: Simple License: BSD3-license-file: LICENSE+License-file: LICENSE Author: Ross Paterson <ross@soi.city.ac.uk> Maintainer: Ross Paterson <ross@soi.city.ac.uk> Homepage: http://www.haskell.org/arrows/+Category: Control Synopsis: Arrow classes and transformers Description: Several classes that extend the Arrow class, and some transformers that implement or lift these classes.