-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Collections and switchable Monad transformers for Reflex -- -- This library provides a set of Monad transformers (and instances for -- common transformers) on top of widget switching primitives for reflex. -- For example ReaderT and WriterT which operate in the presence of -- widget switching, allowing you to pass inputs and outputs up and down -- the UI tree. @package reflex-transformers @version 0.2 module Reflex.Updated -- | Data type for a collection (a map) which is updated by providing -- differences data UpdatedMap t k a UpdatedMap :: (Map k a) -> (Event t (Map k (Maybe a))) -> UpdatedMap t k a -- | Data type for an initial value which is updated, mainly useful for -- it's Functor instance data Updated t a Updated :: a -> (Event t a) -> Updated t a -- | Generalized unzip - probably not the best place for this! split :: Functor f => f (a, b) -> (f a, f b) -- | Hold an Updated as a Dynamic by replacing the initial value -- with updates holdDyn' :: (Reflex t, MonadHold t m, MonadFix m) => Updated t a -> m (Dynamic t a) -- | Hold an Updated as a Behavior by replacing the initial value -- with updates hold' :: (Reflex t, MonadHold t m, MonadFix m) => Updated t a -> m (Behavior t a) -- | Turn an UpdatedMap into a Dynamic by applying the differences to the -- initial value holdMapDyn :: (Reflex t, MonadHold t m, MonadFix m, Ord k) => UpdatedMap t k a -> m (Dynamic t (Map k a)) -- | Hold an UpdatedMap as a behavior by applying differences to the -- initial value holdMap :: (Reflex t, MonadHold t m, MonadFix m, Ord k) => UpdatedMap t k a -> m (Behavior t (Map k a)) -- | Track the shallow (structural) differences between a Behavior and an -- Event shallowDiff :: (Reflex t, Ord k) => Behavior t (Map k a) -> Event t (Map k b) -> Event t (Map k (Maybe b)) -- | Find the shallow (structural) differences between two Maps shallowDiff' :: (Ord k) => Map k a -> Map k b -> Map k (Maybe b) instance Reflex.Class.Reflex t => GHC.Base.Functor (Reflex.Updated.UpdatedMap t k) instance Reflex.Class.Reflex t => GHC.Base.Functor (Reflex.Updated.Updated t) instance Reflex.Class.Reflex t => Control.Lens.Indexed.FunctorWithIndex k (Reflex.Updated.UpdatedMap t k) module Reflex.Switching class (Reflex t) => Switching t r -- | Generalization of switchable reactive types (e.g. Event, Behavior) switching :: (Switching t r, MonadHold t m) => r -> Event t r -> m r class (Switching t r, Monoid r) => SwitchMerge t r -- | Switching for a changing collections of reactive types switchMerge :: (SwitchMerge t r, MonadFix m, MonadHold t m, Ord k) => Map k r -> Event t (Map k (Maybe r)) -> m r -- | Helper which takes an Updated as one argument (instead of initial -- value, update event separately) switching' :: (Reflex t, Switching t r, MonadFix m, MonadHold t m) => Updated t r -> m r -- | Helper which takes an UpdatedMap as one argument (instead of initial -- value, update event separately) switchMerge' :: (Reflex t, SwitchMerge t r, MonadFix m, MonadHold t m, Ord k) => UpdatedMap t k r -> m r instance (Reflex.Switching.Switching t a, Reflex.Switching.Switching t b) => Reflex.Switching.Switching t (a, b) instance (Reflex.Switching.SwitchMerge t a, Reflex.Switching.SwitchMerge t b) => Reflex.Switching.SwitchMerge t (a, b) instance (Data.Semigroup.Semigroup a, Reflex.Class.Reflex t) => Reflex.Switching.SwitchMerge t (Reflex.Class.Event t a) instance (GHC.Base.Monoid a, Reflex.Class.Reflex t) => Reflex.Switching.SwitchMerge t (Reflex.Class.Behavior t a) instance (Reflex.Switching.SwitchMerge t a, GHC.Base.Monoid a, Reflex.Class.Reflex t) => Reflex.Switching.SwitchMerge t [a] instance (Reflex.Switching.Switching t a, GHC.Base.Monoid a, Reflex.Class.Reflex t) => Reflex.Switching.Switching t [a] instance Reflex.Class.Reflex t => Reflex.Switching.SwitchMerge t () instance (GHC.Base.Monoid a, Reflex.Class.Reflex t) => Reflex.Switching.Switching t (Reflex.Class.Behavior t a) instance (Data.Semigroup.Semigroup a, Reflex.Class.Reflex t) => Reflex.Switching.Switching t (Reflex.Class.Event t a) instance Reflex.Class.Reflex t => Reflex.Switching.Switching t () module Reflex.Monad.Class class (MonadReflex t m) => MonadSwitch t m | m -> t where switchM u = do { m <- switchMapM (toMap (Just <$> u)); return $ fromJust <$> fromMap m } -- | Map the result of an initial monadic action and updates and swap it -- out with a new one whenever the event provided fires. returns an -- Updated giving the initial value plus updates switchM :: MonadSwitch t m => Updated t (m a) -> m (Updated t a) -- | Similar to holdM but operating on a collection of widgets provided as -- an UpdatedMap. switchM/switchM' can be implemented in terms of -- switchMapM therefore switchMapM is a minimal implementation. switchMapM :: (MonadSwitch t m, Ord k) => UpdatedMap t k (m a) -> m (UpdatedMap t k a) -- | Constraint type to capture common usage together type MonadReflex t m = (Reflex t, MonadHold t m, MonadFix m) instance Reflex.Monad.Class.MonadSwitch t m => Reflex.Monad.Class.MonadSwitch t (Control.Monad.Trans.Reader.ReaderT e m) instance (Reflex.Monad.Class.MonadSwitch t m, Reflex.Switching.SwitchMerge t w) => Reflex.Monad.Class.MonadSwitch t (Control.Monad.Trans.Writer.Lazy.WriterT w m) module Reflex.Monad.ReflexM -- | Base Monad which sits at the bottom of a (pure) switching Monad -- transformer stack providing the base switching capabilities. newtype ReflexM t a ReflexM :: (forall m. MonadReflex t m => m a) -> ReflexM t a [runReflexM] :: ReflexM t a -> forall m. MonadReflex t m => m a instance GHC.Base.Functor (Reflex.Monad.ReflexM.ReflexM t) instance GHC.Base.Applicative (Reflex.Monad.ReflexM.ReflexM t) instance GHC.Base.Monad (Reflex.Monad.ReflexM.ReflexM t) instance Control.Monad.Fix.MonadFix (Reflex.Monad.ReflexM.ReflexM t) instance Reflex.Class.MonadSample t (Reflex.Monad.ReflexM.ReflexM t) instance Reflex.Class.MonadHold t (Reflex.Monad.ReflexM.ReflexM t) instance Reflex.Class.Reflex t => Reflex.Monad.Class.MonadSwitch t (Reflex.Monad.ReflexM.ReflexM t) module Reflex.Monad.Supply data SupplyT s m a type Supply s a = SupplyT s Identity a runSupplyT :: Monad m => SupplyT s m a -> s -> m (a, s) evalSupplyT :: Monad m => SupplyT s m a -> s -> m a runSupply :: Supply s a -> s -> (a, s) evalSupply :: Supply s a -> s -> a runSplit :: (Monad m, Splitable s i) => SupplyT s m a -> Supply s (m a) getFresh :: (Monad m, Splitable s i) => SupplyT s m i getSplit :: (Monad m, Splitable s i) => SupplyT s m s instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Reflex.Monad.Supply.SupplyT s m) instance Control.Monad.Trans.Class.MonadTrans (Reflex.Monad.Supply.SupplyT s) instance GHC.Base.Monad m => GHC.Base.Monad (Reflex.Monad.Supply.SupplyT s m) instance GHC.Base.Monad m => GHC.Base.Applicative (Reflex.Monad.Supply.SupplyT s m) instance GHC.Base.Functor m => GHC.Base.Functor (Reflex.Monad.Supply.SupplyT s m) instance Control.Monad.Reader.Class.MonadReader st m => Control.Monad.Reader.Class.MonadReader st (Reflex.Monad.Supply.SupplyT s m) instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Reflex.Monad.Supply.SupplyT s m) instance Reflex.Class.MonadSample t m => Reflex.Class.MonadSample t (Reflex.Monad.Supply.SupplyT s m) instance Reflex.Class.MonadHold t m => Reflex.Class.MonadHold t (Reflex.Monad.Supply.SupplyT s m) instance GHC.Enum.Enum a => Reflex.Monad.Supply.Splitable [a] [a] instance Control.Monad.State.Class.MonadState st m => Control.Monad.State.Class.MonadState st (Reflex.Monad.Supply.SupplyT s m) instance (Reflex.Monad.Class.MonadSwitch t m, Reflex.Monad.Supply.Splitable s i) => Reflex.Monad.Class.MonadSwitch t (Reflex.Monad.Supply.SupplyT s m) module Reflex.Monad.ReaderWriter -- | Fusion between ReaderT and WriterT (But not StateT unlike RWST) which -- is switchable using MonadSwitch -- -- Uses implementation based on RSST which implements WriterT using state -- in order to avoid space leaks incurred by the original WriterT data ReaderWriterT r w m a type ReaderWriter r w a = ReaderWriterT r w Identity a runReaderWriterT :: (Monad m, Monoid w) => ReaderWriterT r w m a -> r -> m (a, w) runReaderWriter :: (Monoid w) => ReaderWriter r w a -> r -> (a, w) execReaderWriterT :: (Functor m, Monad m, Monoid w) => ReaderWriterT r w m a -> r -> m w instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.Writer.Class.MonadWriter w (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader r (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance Control.Monad.Trans.Class.MonadTrans (Reflex.Monad.ReaderWriter.ReaderWriterT r w) instance GHC.Base.Monad m => GHC.Base.Monad (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance GHC.Base.Monad m => GHC.Base.Applicative (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance GHC.Base.Functor m => GHC.Base.Functor (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance Reflex.Class.MonadSample t m => Reflex.Class.MonadSample t (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance Reflex.Class.MonadHold t m => Reflex.Class.MonadHold t (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) instance (Reflex.Monad.Class.MonadSwitch t m, Reflex.Switching.SwitchMerge t w) => Reflex.Monad.Class.MonadSwitch t (Reflex.Monad.ReaderWriter.ReaderWriterT r w m) -- | Module supporting the implementation of frameworks. You should import -- this if you want to build your own framework, along with one of the -- base MonadSwitch classes: -- -- Reflex.Monad.App for MonadIO based frameworks or Reflex.Monad.ReflexM -- for pure frameworks module Reflex.Monad -- | Hold a monadic widget and update it whenever the Event provides a new -- monadic widget, swapping out the previously active widget. Returns a -- Dynamic giving the return values of widgets created widgetHold :: (MonadSwitch t m) => m a -> Event t (m a) -> m (Dynamic t a) -- | Provides a view into a Dynamic Map value, where sub-views are created -- using a function passed in returns a Dynamic Map of values returned -- from child views upon creation. mapView :: (MonadSwitch t m, Ord k) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m a) -> m (Dynamic t (Map k a)) -- | Builds a collection of widgets from an initial list and events -- providing new widgets to create as with collect, items remove -- themselves upon the event triggering. returns an UpdatedMap with keys -- assigned to items in ascending order collection :: (MonadSwitch t m) => [m (a, Event t ())] -> Event t [m (a, Event t ())] -> m (UpdatedMap t Int a) -- | Non monadic version of collection, builds a collection from an initial -- list and a list of updated values items remove themselves upon the -- event triggering. returns an UpdatedMap with keys assigned to items in -- ascending order collect :: (MonadReflex t m) => [(a, Event t ())] -> Event t [(a, Event t ())] -> m (UpdatedMap t Int a) -- | Recursive Workflow datatype, see workflow below newtype Workflow t m a Workflow :: m (a, Event t (Workflow t m a)) -> Workflow t m a [unFlow] :: Workflow t m a -> m (a, Event t (Workflow t m a)) -- | Provide a widget which swaps itself out for another widget upon an -- event (recursively) Useful if the sequence of widgets needs to return -- a value (as opposed to passing it down the chain). workflow :: (MonadSwitch t m) => Workflow t m a -> m (Dynamic t a) -- | Data type wrapping chainable widgets of the type (a -> m (Event t -- a)) data Chain t m a b Chain :: (a -> m (Event t b)) -> Chain t m a b (:>>) :: (a -> m (Event t b)) -> Chain t m b c -> Chain t m a c -- | Provide a way of chaining widgets of type (a -> m (Event t b)) -- where one widgets swaps out the old widget. De-couples the return type -- as compared to using workflow chain :: (MonadSwitch t m) => Chain t m a b -> a -> m (Event t b) -- | Compose two Chain values passing the output event of one into -- the construction function of the next. (>->) :: Chain t m a b -> Chain t m b c -> Chain t m a c -- | Provide a way of looping (a -> m (Event t a)), each iteration -- switches out the previous iteration. Can be used with loop :: (MonadSwitch t m) => (a -> m (Event t a)) -> a -> m (Event t a)