arrows 0.4.2.0 → 0.4.3.0
raw patch · 12 files changed
+80/−83 lines, 12 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Arrow.Transformer.CoState: data CoStateArrow s a b c
- Control.Arrow.Transformer.Error: data ErrorArrow ex a b c
- Control.Arrow.Transformer.Reader: data ReaderArrow r a b c
- Control.Arrow.Transformer.State: data StateArrow s a b c
- Control.Arrow.Transformer.Stream: data StreamArrow a b c
- Control.Arrow.Transformer.Writer: data WriterArrow w a b c
+ Control.Arrow.Transformer.CoState: CoStateArrow :: (a (s -> b) (s -> c)) -> CoStateArrow s a b c
+ Control.Arrow.Transformer.CoState: newtype CoStateArrow s a b c
+ Control.Arrow.Transformer.Error: ErrorArrow :: (a b (Either ex c)) -> ErrorArrow ex a b c
+ Control.Arrow.Transformer.Error: newtype ErrorArrow ex a b c
+ Control.Arrow.Transformer.Reader: ReaderArrow :: (a (b, r) c) -> ReaderArrow r a b c
+ Control.Arrow.Transformer.Reader: newtype ReaderArrow r a b c
+ Control.Arrow.Transformer.State: StateArrow :: (a (b, s) (c, s)) -> StateArrow s a b c
+ Control.Arrow.Transformer.State: newtype StateArrow s a b c
+ Control.Arrow.Transformer.Stream: StreamArrow :: (a (Stream b) (Stream c)) -> StreamArrow a b c
+ Control.Arrow.Transformer.Stream: newtype StreamArrow a b c
+ Control.Arrow.Transformer.Writer: WriterArrow :: (a b (c, w)) -> WriterArrow w a b c
+ Control.Arrow.Transformer.Writer: newtype WriterArrow w a b c
Files
- Control/Arrow/Internals.hs +0/−2
- Control/Arrow/Operations.hs +0/−3
- Control/Arrow/Transformer.hs +1/−3
- Control/Arrow/Transformer/Automaton.hs +1/−1
- Control/Arrow/Transformer/CoState.hs +11/−13
- Control/Arrow/Transformer/Error.hs +2/−2
- Control/Arrow/Transformer/Reader.hs +2/−2
- Control/Arrow/Transformer/State.hs +32/−28
- Control/Arrow/Transformer/Static.hs +1/−1
- Control/Arrow/Transformer/Stream.hs +27/−25
- Control/Arrow/Transformer/Writer.hs +2/−2
- arrows.cabal +1/−1
Control/Arrow/Internals.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS_GHC -fglasgow-exts #-}- ----------------------------------------------------------------------------- -- | -- Module : Control.Arrow.Internals
Control/Arrow/Operations.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS_GHC -fglasgow-exts #-}- ----------------------------------------------------------------------------- -- | -- Module : Control.Arrow.Operations@@ -33,7 +31,6 @@ ) where import Control.Arrow-import Control.Category ((>>>)) import Data.Monoid -- $conventions
Control/Arrow/Transformer.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS_GHC -fglasgow-exts #-}- ----------------------------------------------------------------------------- -- | -- Module : Control.Arrow.Transformer@@ -8,7 +6,7 @@ -- -- Maintainer : ross@soi.city.ac.uk -- Stability : experimental--- Portability : non-portable (multi-parameter type classes)+-- Portability : portable -- -- Arrow transformers, for making new arrow types out of old ones.
Control/Arrow/Transformer/Automaton.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |
Control/Arrow/Transformer/CoState.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS_GHC -fglasgow-exts #-}- ----------------------------------------------------------------------------- -- | -- Module : Control.Arrow.Transformer.CoState@@ -15,11 +13,9 @@ -- /TODO:/ define operations for this arrow. module Control.Arrow.Transformer.CoState(- CoStateArrow,+ CoStateArrow(CoStateArrow), ) where -import Control.Arrow.Operations- import Control.Applicative import Control.Arrow import Control.Category@@ -27,15 +23,16 @@ import Prelude hiding (id,(.)) -newtype CoStateArrow s a b c = CST (a (s -> b) (s -> c))+newtype CoStateArrow s a b c = CoStateArrow (a (s -> b) (s -> c)) instance Category a => Category (CoStateArrow s a) where- id = CST id- CST f . CST g = CST (f . g)+ id = CoStateArrow id+ CoStateArrow f . CoStateArrow g = CoStateArrow (f . g) instance Arrow a => Arrow (CoStateArrow s a) where- arr f = CST (arr (f .))- first (CST f) = CST (arr unzipMap >>> first f >>> arr zipMap)+ arr f = CoStateArrow (arr (f .))+ first (CoStateArrow f) =+ CoStateArrow (arr unzipMap >>> first f >>> arr zipMap) zipMap :: (s -> a, s -> b) -> (s -> (a,b)) zipMap h s = (fst h s, snd h s)@@ -48,13 +45,14 @@ -- promotions of standard classes instance ArrowLoop a => ArrowLoop (CoStateArrow s a) where- loop (CST f) = CST (loop (arr zipMap >>> f >>> arr unzipMap))+ loop (CoStateArrow f) =+ CoStateArrow (loop (arr zipMap >>> f >>> arr unzipMap)) instance ArrowZero a => ArrowZero (CoStateArrow s a) where- zeroArrow = CST zeroArrow+ zeroArrow = CoStateArrow zeroArrow instance ArrowPlus a => ArrowPlus (CoStateArrow s a) where- CST f <+> CST g = CST (f <+> g)+ CoStateArrow f <+> CoStateArrow g = CoStateArrow (f <+> g) -- Other instances
Control/Arrow/Transformer/Error.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |@@ -15,7 +15,7 @@ -- /TODO:/ the operations here are inconsistent with other arrow transformers. module Control.Arrow.Transformer.Error(- ErrorArrow,+ ErrorArrow(ErrorArrow), runError, ArrowAddError(..), ) where
Control/Arrow/Transformer/Reader.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |@@ -13,7 +13,7 @@ -- Arrow transformer that adds a read-only state (i.e. an environment). module Control.Arrow.Transformer.Reader(- ReaderArrow,+ ReaderArrow(ReaderArrow), runReader, ArrowAddReader(..), ) where
Control/Arrow/Transformer/State.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |@@ -15,7 +15,7 @@ -- /Science of Computer Programming/ 37:67-111, May 2000. module Control.Arrow.Transformer.State(- StateArrow,+ StateArrow(StateArrow), runState, ArrowAddState(..), ) where@@ -34,21 +34,22 @@ -- | 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))+newtype StateArrow s a b c = StateArrow (a (b, s) (c, s)) swapsnd :: ((a, b), c) -> ((a, c), b) swapsnd ~(~(x, y), z) = ((x, z), y) instance Category a => Category (StateArrow s a) where- id = ST id- ST f . ST g = ST (f . g)+ id = StateArrow id+ StateArrow f . StateArrow g = StateArrow (f . g) instance Arrow a => Arrow (StateArrow s a) where- arr f = ST (arr (\(x, s) -> (f x, s)))- first (ST f) = ST (arr swapsnd >>> first f >>> arr swapsnd)+ arr f = StateArrow (arr (\(x, s) -> (f x, s)))+ first (StateArrow f) =+ StateArrow (arr swapsnd >>> first f >>> arr swapsnd) instance Arrow a => ArrowTransformer (StateArrow s) a where- lift f = ST (first f)+ lift f = StateArrow (first f) -- | Encapsulation of a state-using computation, exposing the initial -- and final states.@@ -60,13 +61,13 @@ -- > (result, final_state) <- (|runState cmd|) init_state runState :: Arrow a => StateArrow s a e b -> a (e,s) (b,s)-runState (ST f) = f+runState (StateArrow f) = f -- operations instance Arrow a => ArrowState s (StateArrow s a) where- fetch = ST (arr (\(_, s) -> (s, s)))- store = ST (arr (\(s, _) -> ((), s)))+ fetch = StateArrow (arr (\(_, s) -> (s, s)))+ store = StateArrow (arr (\(s, _) -> ((), s))) instance Arrow a => ArrowAddState s (StateArrow s a) a where liftState = lift@@ -75,18 +76,19 @@ -- The following promotions follow directly from the arrow transformer. instance ArrowZero a => ArrowZero (StateArrow s a) where- zeroArrow = ST zeroArrow+ zeroArrow = StateArrow zeroArrow instance ArrowCircuit a => ArrowCircuit (StateArrow s a) where delay x = lift (delay x) instance ArrowError ex a => ArrowError ex (StateArrow s a) where raise = lift raise- handle (ST f) (ST h) = ST (handle f (arr swapsnd >>> h))- tryInUnless (ST f) (ST s) (ST h) =- ST (tryInUnless f (arr new_state >>> s) (arr swapsnd >>> h))+ handle (StateArrow f) (StateArrow h) =+ StateArrow (handle f (arr swapsnd >>> h))+ tryInUnless (StateArrow f) (StateArrow s) (StateArrow h) =+ StateArrow (tryInUnless f (arr new_state >>> s) (arr swapsnd >>> h)) where new_state ((b,_),(c,s')) = ((b,c),s')- newError (ST f) = ST (newError f &&& arr snd >>> arr h)+ newError (StateArrow f) = StateArrow (newError f &&& arr snd >>> arr h) where h (Left ex, s) = (Left ex, s) h (Right (c, s'), _) = (Right c, s') @@ -94,29 +96,30 @@ instance ArrowReader r a => ArrowReader r (StateArrow s a) where readState = lift readState- newReader (ST f) = ST (arr swapsnd >>> newReader f)+ newReader (StateArrow f) = StateArrow (arr swapsnd >>> newReader f) instance ArrowWriter w a => ArrowWriter w (StateArrow s a) where write = lift write- newWriter (ST f) = ST (newWriter f >>> arr swapsnd)+ newWriter (StateArrow f) = StateArrow (newWriter f >>> arr swapsnd) -- liftings of standard classes instance ArrowChoice a => ArrowChoice (StateArrow s a) where- left (ST f) = ST (arr distr >>> left f >>> arr undistr)+ left (StateArrow f) = StateArrow (arr distr >>> left f >>> arr undistr) where distr (Left y, s) = Left (y, s) distr (Right z, s) = Right (z, s) undistr (Left (y, s)) = (Left y, s) undistr (Right (z, s)) = (Right z, s) instance ArrowApply a => ArrowApply (StateArrow s a) where- app = ST (arr (\((ST f, x), s) -> (f, (x, s))) >>> app)+ app = StateArrow (arr (\((StateArrow f, x), s) -> (f, (x, s))) >>> app) instance ArrowLoop a => ArrowLoop (StateArrow s a) where- loop (ST f) = ST (loop (arr swapsnd >>> f >>> arr swapsnd))+ loop (StateArrow f) =+ StateArrow (loop (arr swapsnd >>> f >>> arr swapsnd)) instance ArrowPlus a => ArrowPlus (StateArrow s a) where- ST f <+> ST g = ST (f <+> g)+ StateArrow f <+> StateArrow g = StateArrow (f <+> g) -- Other instances @@ -139,15 +142,16 @@ instance ArrowAddReader r a a' => ArrowAddReader r (StateArrow s a) (StateArrow s a') where- liftReader (ST f) = ST (liftReader f)- elimReader (ST f) = ST (arr swapsnd >>> elimReader f)+ liftReader (StateArrow f) = StateArrow (liftReader f)+ elimReader (StateArrow f) = StateArrow (arr swapsnd >>> elimReader f) instance ArrowAddWriter w a a' => ArrowAddWriter w (StateArrow s a) (StateArrow s a') where- liftWriter (ST f) = ST (liftWriter f)- elimWriter (ST f) = ST (elimWriter f >>> arr swapsnd)+ liftWriter (StateArrow f) = StateArrow (liftWriter f)+ elimWriter (StateArrow f) = StateArrow (elimWriter f >>> arr swapsnd) instance ArrowAddError ex a a' => ArrowAddError ex (StateArrow s a) (StateArrow s a') where- liftError (ST f) = ST (liftError f)- elimError (ST f) (ST h) = ST (elimError f (arr swapsnd >>> h))+ liftError (StateArrow f) = StateArrow (liftError f)+ elimError (StateArrow f) (StateArrow h) =+ StateArrow (elimError f (arr swapsnd >>> h))
Control/Arrow/Transformer/Static.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |
Control/Arrow/Transformer/Stream.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances, Rank2Types #-} ----------------------------------------------------------------------------- -- |@@ -13,7 +13,7 @@ -- Arrow transformer lifting an arrow to streams. module Control.Arrow.Transformer.Stream(- StreamArrow,+ StreamArrow(StreamArrow), runStream, StreamMap, StreamMapST, runStreamST,@@ -38,16 +38,16 @@ -- -- /Note/: 'lift' is only a functor if '***' in the underlying arrow is. -newtype StreamArrow a b c = Str (a (Stream b) (Stream c))+newtype StreamArrow a b c = StreamArrow (a (Stream b) (Stream c)) instance Category a => Category (StreamArrow a) where- id = Str id- Str f . Str g = Str (f . g)+ id = StreamArrow id+ StreamArrow f . StreamArrow g = StreamArrow (f . g) instance Arrow a => Arrow (StreamArrow a) where- arr f = Str (arr (fmap f))- first (Str f) =- Str (arr Stream.unzip >>> first f >>> arr (uncurry Stream.zip))+ arr f = StreamArrow (arr (fmap f))+ first (StreamArrow f) =+ StreamArrow (arr Stream.unzip >>> first f >>> arr (uncurry Stream.zip)) genmap :: Arrow a => a b c -> a (Stream b) (Stream c) genmap f = arr (\xs -> (Stream.head xs, Stream.tail xs)) >>>@@ -59,7 +59,7 @@ -- but won't preserve composition unless *** does. instance Arrow a => ArrowTransformer (StreamArrow) a where- lift f = Str (genmap f)+ lift f = StreamArrow (genmap f) -- The following promotions follow directly from the arrow transformer. @@ -72,27 +72,28 @@ instance ArrowWriter w a => ArrowWriter w (StreamArrow a) where write = lift write- newWriter (Str f) = Str (newWriter f >>> arr strength)- where strength :: Functor w' => (w' a',b) -> w' (a',b)- strength (v, y) = fmap (\x -> (x, y)) v+ newWriter (StreamArrow f) = StreamArrow (newWriter f >>> arr strength)+ where strength :: Functor w' => (w' a',b) -> w' (a',b)+ strength (v, y) = fmap (\x -> (x, y)) v -- liftings of standard classes instance Arrow a => ArrowChoice (StreamArrow a) where- left (Str f) = Str ((arr getLeft >>> f) &&& arr id >>> arr replace)- where getLeft (Cons (Left x) xs) = Cons x (getLeft xs)- getLeft (Cons (Right _) xs) = getLeft xs- replace (~(Cons x xs), Cons (Left _) ys) =- Cons (Left x) (replace (xs, ys))- replace (xs, Cons (Right y) ys) =- Cons (Right y) (replace (xs, ys))+ left (StreamArrow f) =+ StreamArrow ((arr getLeft >>> f) &&& arr id >>> arr replace)+ where getLeft (Cons (Left x) xs) = Cons x (getLeft xs)+ getLeft (Cons (Right _) xs) = getLeft xs+ replace (~(Cons x xs), Cons (Left _) ys) =+ Cons (Left x) (replace (xs, ys))+ replace (xs, Cons (Right y) ys) =+ Cons (Right y) (replace (xs, ys)) instance ArrowLoop a => ArrowLoop (StreamArrow a) where- loop (Str f) =- Str (loop (arr (uncurry Stream.zip) >>> f >>> arr Stream.unzip))+ loop (StreamArrow f) =+ StreamArrow (loop (arr (uncurry Stream.zip) >>> f >>> arr Stream.unzip)) instance ArrowPlus a => ArrowPlus (StreamArrow a) where- Str f <+> Str g = Str (f <+> g)+ StreamArrow f <+> StreamArrow g = StreamArrow (f <+> g) -- I don't know of any other useful promotions. -- (elimWriter can be promoted, but doesn't seem useful.)@@ -100,7 +101,7 @@ -- Circuits instance ArrowLoop a => ArrowCircuit (StreamArrow a) where- delay x = Str (arr (Cons x))+ delay x = StreamArrow (arr (Cons x)) -- Other instances @@ -132,7 +133,7 @@ -- elements of that stream. @ys@ is bound to the output stream. runStream :: ArrowLoop a => StreamArrow a (e,b) c -> a (e,Stream b) (Stream c)-runStream (Str f) = arr (\(e, xs) -> fmap (\x -> (e, x)) xs) >>> f+runStream (StreamArrow f) = arr (\(e, xs) -> fmap (\x -> (e, x)) xs) >>> f instance ArrowLoop a => ArrowAddStream (StreamArrow a) a where liftStream = lift@@ -156,4 +157,5 @@ -- | Encapsulate a local state. runStreamST :: (forall s. StreamMapST s e c) -> StreamMap e c-runStreamST cf = Str $ \ input -> runST (let Str (Kleisli f) = cf in f input)+runStreamST cf = StreamArrow $ \ input ->+ runST (let StreamArrow (Kleisli f) = cf in f input)
Control/Arrow/Transformer/Writer.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE FlexibleInstances #-} ----------------------------------------------------------------------------- -- |@@ -13,7 +13,7 @@ -- Arrow transformer that adds accumulation of output. module Control.Arrow.Transformer.Writer(- WriterArrow,+ WriterArrow(WriterArrow), runWriter, ArrowAddWriter(..), ) where
arrows.cabal view
@@ -1,5 +1,5 @@ Name: arrows-Version: 0.4.2.0+Version: 0.4.3.0 Build-Depends: base >= 4.0 && < 6, Stream Build-Type: Simple License: BSD3