auto 0.4.2.0 → 0.4.2.1
raw patch · 6 files changed
+67/−7 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−2
- auto.cabal +1/−1
- src/Control/Auto/Collection.hs +5/−0
- src/Control/Auto/Core.hs +8/−0
- src/Control/Auto/Effects.hs +38/−4
- src/Control/Auto/Process/Random.hs +7/−0
CHANGELOG.md view
@@ -1,8 +1,14 @@+0.4.2.1+-------+<https://github.com/mstksg/auto/releases/tag/v0.4.2.1>++* Added support for building with GHC 7.6.x.+ 0.4.2.0 ------- <https://github.com/mstksg/auto/releases/tag/v0.4.2.0> -* Removed all upper bounds on dependencies.+* Removed all upper bounds on dependencies except for base. * **Control.Auto.Blip**: Companions to `emitJusts` and `onJusts` added, for `Either`: `emitEithers` and `onEithers`. Emit every item inputted, but fork them into one of two output blit streams based on `Right` or `Left`@@ -28,7 +34,7 @@ `muxMany`, `muxI` and `muxManyI`. They store `Interval`s instead of `Auto`s...and when the `Interval`s turned "off", they are removed from the collection.-* **Control.Auto.Switch**: A new "count-down" swithcer, `switchIn`, which+* **Control.Auto.Switch**: A new "count-down" switcher, `switchIn`, which acts a bit like `(-->)` and `(-?>)`, except the switch happens deterministically after a pre-set given number of steps. Act like the first `Auto` for a given number of steps, and then act like the second
auto.cabal view
@@ -1,5 +1,5 @@ name: auto-version: 0.4.2.0+version: 0.4.2.1 synopsis: Denotative, locally stateful programming DSL & platform description: (Up to date documentation is maintained at <https://mstksg.github.com/auto>)
src/Control/Auto/Collection.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RankNTypes #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} @@ -98,6 +99,10 @@ import Prelude hiding (mapM, mapM_, concat, sequence, (.), id, sequence_) import qualified Data.IntMap.Strict as IM import qualified Data.Map.Strict as M++#if !MIN_VERSION_base(4,7,0)+import Compat()+#endif -- | Give a list of @'Auto' m a b@ and get back an @'Auto' m [a] [b]@ --- -- take a list of @a@'s and feed them to each of the 'Auto's, and collects
src/Control/Auto/Core.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE TupleSections #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE RankNTypes #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE ExistentialQuantification #-} -- |@@ -111,7 +112,11 @@ import Data.Typeable import Prelude hiding ((.), id, sequence) +#if !MIN_VERSION_base(4,7,0)+import Compat()+#endif + -- | The 'Auto' type. For this library, an 'Auto' semantically -- represents/denotes a /a relationship/ between an input and an -- output that is preserved over multiple steps, where that relationship is@@ -198,7 +203,10 @@ | forall s. AutoStateM (Get s, s -> Put) !(a -> s -> m (b, s)) !s | AutoArb (Get (Auto m a b)) Put !(a -> (b, Auto m a b)) | AutoArbM (Get (Auto m a b)) Put !(a -> m (b, Auto m a b))+#if MIN_VERSION_base(4,7,0) deriving ( Typeable )+#endif+ -- | Special case of 'Auto' where the underlying 'Monad' is 'Identity'. --
src/Control/Auto/Effects.hs view
@@ -411,9 +411,9 @@ -- that always gets its environment value by executing an action every step -- in the underlying monad. ----- This can be abused to write unreadable code really fast if you don't use--- it in a disciplined way. One possible usage is to query a database in--- 'IO' (or 'MonadIO') for a value at every step. If you're using+-- This can be abused to write unmaintainble code really fast if you don't+-- use it in a disciplined way. One possible usage is to query a database+-- in 'IO' (or 'MonadIO') for a value at every step. If you're using -- underlying global state, you can use it to query that too, with 'get' or -- 'gets'. You could even use 'getLine', maybe, to get the result from -- standard input at every step.@@ -671,7 +671,7 @@ -- Consider this example 'State' 'Auto': -- -- @--- foo :: Auto (State s) Int Int+-- foo :: Auto (State Int) Int Int -- foo = proc x -> do -- execB (modify (+1)) . emitOn odd -< x -- execB (modify (*2)) . emitOn even -< x@@ -727,6 +727,17 @@ -- stream is the result of running the stream through @f@, first with an -- initial state of @s0@, and afterwards with each next updated state. --+-- If you wanted to "seal" the state and have it be untouchable to the+-- outside world, yet still have a way to "monitor"/"view" it, you can+-- modify the original 'Auto' using '&&&', 'effect', and 'get to get+-- a "view" of the state:+--+-- >>> streamAuto' (sealState (foo &&& effect get) 5) [1..10]+-- [(7,6),(15,12),(19,13),(36,26),(42,27),(75,54),(83,55),(146,110),(156,111),(277,222)]+--+-- Now, every output of @'sealState' foo 5@ is tuplied up with a peek of+-- its state at that point.+-- -- For a convenient way of "creating" an 'Auto' under 'StateT' in the first -- place, see 'stateA'. --@@ -751,6 +762,29 @@ ((y, a'), s1) <- runStateT (stepAuto a x) s0 return (y, sealState_ a' s1) +sealStateM :: Monad m+ => Auto (StateT s m) a b -- ^ 'Auto' run over 'State'+ -> m s -- ^ action to draw new @s@ at every step+ -> (s -> m ()) -- ^ action to "update" the state at every step+ -> Auto m a b+sealStateM a0 gt pt = go a0+ where+ go a = mkAutoM (go <$> resumeAuto a)+ (saveAuto a)+ $ \x -> do+ s <- gt+ ((y, a'), s') <- runStateT (stepAuto a x) s+ pt s'+ return (y, go a')++sealStateMVar :: MonadIO m+ => Auto (StateT s m) a b -- ^ 'Auto' run over 'State'+ -> MVar s -- ^ 'MVar' containing an @s@ for every step+ -> Auto m a b+sealStateMVar a0 mv = sealStateM a0+ (liftIO $ takeMVar mv)+ (liftIO . putMVar mv )+-- TODO: Masking? -- | "Unrolls" the underlying 'StateT' of an 'Auto' into an 'Auto' that -- takes in an input state every turn (in addition to the normal input) and
src/Control/Auto/Process/Random.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | -- Module : Control.Auto.Process.Random -- Description : Entropy generationg 'Auto's.@@ -136,6 +138,11 @@ import Data.Serialize import Data.Tuple import Prelude hiding (id, (.), concat, concatMap, sum)++#if !MIN_VERSION_base(4,7,0)+import Compat()+#endif+ -- | Given a seed-consuming generating function of form @g -> (b, g)@ -- (where @g@ is the seed, and @b@ is the result) and an initial seed,