packages feed

reflex-transformers 0.2 → 0.2.1

raw patch · 3 files changed

+31/−5 lines, 3 files

Files

reflex-transformers.cabal view
@@ -1,5 +1,5 @@ name:          reflex-transformers-version:       0.2+version:       0.2.1 license:       BSD3 license-file:  LICENSE cabal-version: >= 1.10
src/Reflex/Monad.hs view
@@ -171,3 +171,17 @@   return (never, toFlow c <$> e)      +  +-- sequenceEvents :: (MonadSwitch t m, Ord k) => UpdatedMap k (Event t a -> m (Event t a)) ->  Event t a -> m (Event t a)+-- sequenceEvents items input = do+--   rec +--     let input k     = switch (previous k <$> b)+--         previous k  = fromMaybe input . Map.lookupLT k+--   +--     b <- holdMap outputs+--     outputs <- holdMapM $ imap (\k f -> f (input k)) items+--     +--   return (switch $ fromMaybe input . fmap fst .  Map.maxView <$> b)+--   +  +
src/Reflex/Monad/Supply.hs view
@@ -4,6 +4,9 @@ module Reflex.Monad.Supply   ( SupplyT    , Supply+  +  , Splitable(..)+     , runSupplyT   , evalSupplyT @@ -37,6 +40,10 @@ import Prelude  +-- | Abstraction for splittable identifier supplies, priovided is an instance for Enum a => [a]  +-- but a more efficient supply would be for example, found in the concurrent-supply package.+-- at the cost of determinism.+-- Two parameters, a state 's' and an identifier type 'i' class Splitable s i | s -> i where      freshId :: s -> (i, s)@@ -53,7 +60,8 @@     where xs' = snd (freshId xs)      -    +-- | ID Supply transformer for switchable reflex stacks over splittable ID supplies+-- Fresh variables are obtained using getFresh. Admits a MonadSwitch instance.  newtype SupplyT s m a = SupplyT (StateT s m a)   deriving (Functor, Applicative, Monad, MonadTrans, MonadFix)   @@ -64,27 +72,31 @@ deriving instance MonadSample t m => MonadSample t (SupplyT s m) deriving instance MonadHold t m => MonadHold t (SupplyT s m) +-- | Non transformer version type Supply s a = SupplyT s Identity a -  + instance MonadState st m => MonadState st (SupplyT s m)  where   get = lift get   put = lift . put -+-- | Obtain a fresh ID from the Supply getFresh :: (Monad m, Splitable s i) => SupplyT s m i getFresh = SupplyT $ state freshId  +-- | Obtain a value of the ID Supply which provides distinct ids from those +-- returned from the Monad in future. getSplit :: (Monad m, Splitable s i) => SupplyT s m s getSplit = SupplyT $ state splitSupply  -+-- | Run a non transformer Supply using a split  runSplit ::  (Monad m, Splitable s i) =>  SupplyT s m a -> Supply s (m a) runSplit m = evalSupplyT m <$> getSplit    +-- | Run a SupplyT with a Spittable state runSupplyT :: Monad m => SupplyT s m a -> s -> m (a, s) runSupplyT (SupplyT m) = runStateT m