-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple foundation for functional reactive programming -- -- Reactive is a simple foundation for programming reactive -- systems functionally. Like Fran/FRP, it has a notions of (reactive) -- behaviors and events. Unlike most previous FRP implementations, -- Reactive has a hybrid demand/data-driven implementation, as described -- in the paper "Simply efficient functional reactivity", -- http://conal.net/papers/simply-reactive/. -- -- Import FRP.Reactive for FRP client apps. To make an Reactive -- adapter for an imperative library, import -- FRP.Reactive.LegacyAdapters. -- -- Please see the project wiki page: -- http://haskell.org/haskellwiki/reactive -- -- © 2007-2008 by Conal Elliott; BSD3 license. -- -- With contributions from: Robin Green, Thomas Davie, Luke Palmer, David -- Sankel, Jules Bean, Creighton Hogg, and Chuan-kai Lin. Please let me -- know if I've forgotten to list you. @package reactive @version 0.9.7 -- | Serialize actions. module FRP.Reactive.Internal.Serial -- | Serializer. Turns actions into equivalent but serialized actions type Serial = forall a. IO a -> IO a -- | Make a locking serializer makeSerial :: IO Serial -- | Make a locking serializer with a given lock locking :: MVar () -> Serial -- | Write-once variables. module FRP.Reactive.Internal.IVar data IVar a newEmptyIVar :: IO (IVar a) -- | Returns the value in the IVar. The *value* will block until the -- variable becomes filled. readIVar :: IVar a -> a -- | Returns Nothing if the IVar has no value yet, otherwise returns the -- value. tryReadIVar :: IVar a -> IO (Maybe a) -- | Puts the value of the IVar. If it already has a value, block forever. writeIVar :: IVar a -> a -> IO () -- | Writer monad as a pair. Until it's in Control.Monad.Instances. -- -- Use import Data.PairMonad () module Data.PairMonad instance (Monoid o) => Monad ((,) o) -- | Max monoid module Data.Max -- | Ordered monoid under max. newtype Max a Max :: a -> Max a getMax :: Max a -> a instance (Eq a) => Eq (Max a) instance (Ord a) => Ord (Max a) instance (Bounded a) => Bounded (Max a) instance (Read a) => Read (Max a) instance (Show a) => Show (Max a) instance (EqProp a) => EqProp (Max a) instance (Arbitrary a) => Arbitrary (Max a) instance (Ord a, Bounded a) => Monoid (Max a) -- | Min monoid module Data.Min -- | Ordered monoid under min. newtype Min a Min :: a -> Min a getMin :: Min a -> a instance (Eq a) => Eq (Min a) instance (Ord a) => Ord (Min a) instance (Read a) => Read (Min a) instance (Show a) => Show (Min a) instance (Bounded a) => Bounded (Min a) instance (EqProp a) => EqProp (Min a) instance (Arbitrary a) => Arbitrary (Min a) instance (Ord a, Bounded a) => Monoid (Min a) -- | Add bounds to an ordered type module Data.AddBounds -- | Wrap a type into one having new least and greatest elements, -- preserving the existing ordering. data AddBounds a MinBound :: AddBounds a NoBound :: a -> AddBounds a MaxBound :: AddBounds a instance (Eq a) => Eq (AddBounds a) instance (Read a) => Read (AddBounds a) instance (Show a) => Show (AddBounds a) instance (EqProp a, Eq a) => EqProp (AddBounds a) instance (Arbitrary a) => Arbitrary (AddBounds a) instance (Ord a) => Ord (AddBounds a) instance Bounded (AddBounds a) -- | Constant-optimized representation of functions. module FRP.Reactive.Internal.Fun -- | Constant-optimized functions data Fun t a -- | constant function K :: a -> Fun t a -- | non-constant function Fun :: (t -> a) -> Fun t a -- | Misc Reactive internal defs module FRP.Reactive.Internal.Misc -- | Convenient alias for dropping parentheses. type Action = IO () -- | Value consumer type Sink a = a -> Action -- | Representation of future values module FRP.Reactive.Internal.Future -- | Time used in futures. The parameter t can be any Ord -- type. The added bounds represent -Infinity and +Infinity. Pure values -- have time minBound (-Infinity), while never-occurring futures have -- time maxBound (+Infinity). type Time t = Max (AddBounds t) -- | A future value of type a with time type t. Simply a -- time/value pair. Particularly useful with time types that have -- non-flat structure. newtype FutureG t a Future :: (Time t, a) -> FutureG t a unFuture :: FutureG t a -> (Time t, a) -- | Apply a unary function within the FutureG representation. inFuture :: ((Time t, a) -> (Time t', b)) -> FutureG t a -> FutureG t' b -- | Apply a binary function within the FutureG representation. inFuture2 :: ((Time t, a) -> (Time t', b) -> (Time t', c)) -> FutureG t a -> FutureG t' b -> FutureG t' c -- | Run a future in the current thread. Use the given time sink to sync -- time, i.e., to wait for an output time before performing the action. runF :: (Ord t) => Sink t -> FutureG t (IO a) -> IO a instance Functor (FutureG t) instance (Ord t) => Applicative (FutureG t) instance (Ord t) => Monad (FutureG t) instance Copointed (FutureG t) instance Comonad (FutureG t) instance (Show t, Show a) => Show (FutureG t a) instance (Arbitrary t, Arbitrary a) => Arbitrary (FutureG t a) -- | Representation for Reactive and Event types. Combined here, -- because they're mutually recursive. -- -- The representation used in this module is based on a close connection -- between these two types. A reactive value is defined by an initial -- value and an event that yields future values; while an event is given -- as a future reactive value. module FRP.Reactive.Internal.Reactive -- | Events. Semantically: time-ordered list of future values. Instances: -- -- newtype EventG t a Event :: FutureG t (ReactiveG t a) -> EventG t a eFuture :: EventG t a -> FutureG t (ReactiveG t a) -- | Apply a unary function inside an EventG representation. inEvent :: (FutureG s (ReactiveG s a) -> FutureG t (ReactiveG t b)) -> (EventG s a -> EventG t b) -- | Apply a unary function inside an EventG representation. inEvent2 :: (FutureG t (ReactiveG t a) -> FutureG t (ReactiveG t b) -> FutureG t (ReactiveG t c)) -> (EventG t a -> EventG t b -> EventG t c) -- | Make the event into a list of futures eFutures :: EventG t a -> [FutureG t a] -- | Reactive value: a discretely changing value. Reactive values can be -- understood in terms of (a) a simple denotational semantics of reactive -- values as functions of time, and (b) the corresponding instances for -- functions. The semantics is given by the function at :: ReactiveG -- t a -> (t -> a). A reactive value may also be thought of -- (and in this module is implemented as) a current value and an event -- (stream of future values). -- -- The semantics of ReactiveG instances are given by corresponding -- instances for the semantic model (functions): -- -- data ReactiveG t a Stepper :: a -> EventG t a -> ReactiveG t a -- | Apply a unary function inside the rEvent part of a Reactive -- representation. inREvent :: (EventG s a -> EventG t a) -> (ReactiveG s a -> ReactiveG t a) -- | Apply a unary function inside the future reactive inside a Reactive -- representation. inFutR :: (FutureG s (ReactiveG s b) -> FutureG t (ReactiveG t b)) -> (ReactiveG s b -> ReactiveG t b) -- | Run an event in the current thread. Use the given time sink to sync -- time, i.e., to wait for an output time before performing the action. runE :: (Ord t) => Sink t -> Sink (EventG t Action) -- | Run a reactive value in the current thread, using the given time sink -- to sync time. runR :: (Ord t) => Sink t -> Sink (ReactiveG t Action) -- | Run an event in a new thread, using the given time sink to sync time. forkE :: (Ord t) => Sink t -> EventG t Action -> IO ThreadId -- | Run a reactive value in a new thread, using the given time sink to -- sync time. The initial action happens in the current thread. forkR :: (Ord t) => Sink t -> ReactiveG t Action -> IO ThreadId instance (Show x, Show y) => Show (ReactiveG x y) instance (Show a, Show b) => Show (EventG a b) -- | Improving values -- efficient version module FRP.Reactive.Improving -- | An improving value. data Improving a Imp :: a -> (a -> Ordering) -> Improving a exact :: Improving a -> a compareI :: Improving a -> a -> Ordering -- | A known improving value (which doesn't really improve) exactly :: (Ord a) => a -> Improving a -- | Efficient combination of min and '(<=)' minI :: (Ord a) => Improving a -> Improving a -> (Improving a, Bool) -- | Efficient combination of max and '(>=)' maxI :: (Ord a) => Improving a -> Improving a -> (Improving a, Bool) instance (EqProp a) => EqProp (Improving a) instance (Ord a) => Ord (Improving a) instance (Eq a) => Eq (Improving a) -- | Functions, with constant functions optimized, with instances for many -- standard classes. module FRP.Reactive.Fun -- | Constant-optimized functions data Fun t a fun :: (t -> a) -> Fun t a -- | Fun as a function apply :: Fun t a -> (t -> a) batch :: TestBatch instance (Monoid t) => Comonad (Fun t) instance (Monoid t) => Copointed (Fun t) instance Pointed (Fun t) instance Arrow Fun instance Category Fun instance Monad (Fun t) instance Applicative (Fun t) instance Zip (Fun t) instance Functor (Fun t) instance (Monoid a) => Monoid (Fun t a) instance Model1 (Fun a) ((->) a) instance Model (Fun a b) (a -> b) instance (Show a, Arbitrary a, EqProp a, EqProp b) => EqProp (Fun a b) instance (Show b) => Show (Fun a b) instance (Arbitrary a, Arbitrary b) => Arbitrary (Fun a b) -- | A simple formulation of functional futures, roughly as -- described at http://en.wikipedia.org/wiki/Futures_and_promises. -- -- A future is a value with an associated time of arrival. -- Typically, neither the time nor the value can be known until the -- arrival time. -- -- Primitive futures can be things like /the value of the next key you -- press, or the value of LambdaPix stock at noon next Monday/. -- -- Composition is via standard type classes: Functor, Applicative, -- Monad, and Monoid. Some comments on the Future -- instances of these classes: -- -- -- -- Futures are parametric over time as well as value types. -- The time parameter can be any ordered type and is particularly useful -- with time types that have rich partial information structure, such as -- /improving values/. module FRP.Reactive.Future -- | Time used in futures. The parameter t can be any Ord -- type. The added bounds represent -Infinity and +Infinity. Pure values -- have time minBound (-Infinity), while never-occurring futures have -- time maxBound (+Infinity). type Time t = Max (AddBounds t) -- | Make a finite time ftime :: t -> Time t -- | A future value of type a with time type t. Simply a -- time/value pair. Particularly useful with time types that have -- non-flat structure. newtype FutureG t a Future :: (Time t, a) -> FutureG t a unFuture :: FutureG t a -> (Time t, a) -- | Apply a unary function within the FutureG representation. inFuture :: ((Time t, a) -> (Time t', b)) -> FutureG t a -> FutureG t' b -- | Apply a binary function within the FutureG representation. inFuture2 :: ((Time t, a) -> (Time t', b) -> (Time t', c)) -> FutureG t a -> FutureG t' b -> FutureG t' c -- | A future's time futTime :: FutureG t a -> Time t -- | A future's value futVal :: FutureG t a -> a -- | A future value with given time & value future :: t -> a -> FutureG t a -- | Access time of future withTimeF :: FutureG t a -> FutureG t (Time t, a) batch :: TestBatch instance (EqProp t) => EqProp (TimeInfo t) instance (Ord a) => Ord (TimeInfo a) instance (Eq a) => Eq (TimeInfo a) instance (Ord t) => Monoid (FutureG t a) instance (EqProp t, Eq t, EqProp a) => EqProp (FutureG t a) -- | Functional events and reactive values. Semantically, an -- Event is stream of future values in time order. A Reactive -- value is a discretly time-varying value. -- -- Many of the operations on events and reactive values are packaged as -- instances of the standard type classes Monoid, Functor, -- Applicative, and Monad. -- -- This module focuses on representation and primitives defined in terms -- of the representation. See also FRP.Reactive.Reactive, which -- re-exports this module, plus extras that do not exploit the -- representation. My intention for this separation is to ease -- experimentation with alternative representations. -- -- Although the basic Reactive type describes discretely-changing -- values, continuously-changing values can be modeled simply as -- reactive functions. See FRP.Reactive.Behavior for a convenient -- type composition of Reactive and a constant-optimized representation -- of functions of time. The exact packaging of discrete vs continuous -- will probably change with more experience. module FRP.Reactive.PrimReactive -- | Events. Semantically: time-ordered list of future values. Instances: -- -- data EventG t a -- | Reactive value: a discretely changing value. Reactive values can be -- understood in terms of (a) a simple denotational semantics of reactive -- values as functions of time, and (b) the corresponding instances for -- functions. The semantics is given by the function at :: ReactiveG -- t a -> (t -> a). A reactive value may also be thought of -- (and in this module is implemented as) a current value and an event -- (stream of future values). -- -- The semantics of ReactiveG instances are given by corresponding -- instances for the semantic model (functions): -- -- data ReactiveG t a -- | Reactive value from an initial value and a new-value event. stepper :: a -> EventG t a -> ReactiveG t a -- | Switch between reactive values. switcher :: (Ord t) => ReactiveG t a -> EventG t (ReactiveG t a) -> ReactiveG t a -- | Access occurrence times in an event. See also withTimeGR. withTimeGE :: EventG t a -> EventG t (a, Time t) -- | Access occurrence times in a reactive value. See also -- withTimeGE. withTimeGR :: Time t -> ReactiveG t a -> ReactiveG t (a, Time t) -- | Convert a temporally monotonic list of futures to an event futuresE :: (Ord t) => [FutureG t a] -> EventG t a -- | Convert a temporally monotonic list of futures to an event. See also -- the specialization listE listEG :: (Ord t) => [(t, a)] -> EventG t a -- | Event at given times. See also atTimeG. atTimesG :: (Ord t) => [t] -> EventG t () -- | Single-occurrence event at given time. atTimeG :: (Ord t) => t -> EventG t () -- | Snapshot a reactive value whenever an event occurs and apply a -- combining function to the event and reactive's values. snapshotWith :: (Ord t) => (a -> b -> c) -> EventG t a -> ReactiveG t b -> EventG t c -- | Accumulating event, starting from an initial value and a -- update-function event. See also accumR. accumE :: a -> EventG t (a -> a) -> EventG t a -- | Reactive value from an initial value and an updater event. See also -- accumE. accumR :: a -> EventG t (a -> a) -> ReactiveG t a -- | Just the first occurrence of an event. once :: (Ord t) => EventG t a -> EventG t a -- | Access the remainder with each event occurrence. withRestE :: EventG t a -> EventG t (a, EventG t a) -- | Truncate first event at first occurrence of second event. untilE :: (Ord t) => EventG t a -> EventG t b -> EventG t a -- | Pass through the Just occurrences, stripped. Experimental -- specialization of joinMaybes. justE :: (Ord t) => EventG t (Maybe a) -> EventG t a -- | Pass through values satisfying a given predicate. Experimental -- specialization of filterMP. filterE :: (Ord t, Show a) => (a -> Bool) -> EventG t a -> EventG t a -- | Extract a future representing the first occurrence of the event -- together with the event of all occurrences after that one. eventOcc :: (Ord t) => EventG t a -> FutureG t (a, EventG t a) -- | Pass through Just occurrences. joinMaybes :: (MonadPlus m) => m (Maybe a) -> m a -- | Pass through values satisfying p. filterMP :: (MonadPlus m) => (a -> Bool) -> m a -> m a -- | Apply a given function inside the results of other functions. -- Equivalent to '(.)', but has a nicer reading when composed result :: (b -> b') -> ((a -> b) -> (a -> b')) isMonotoneR :: (Ord t) => ReactiveG t a -> Bool batch :: TestBatch infE :: EventG NumT NumT instance (Monoid t) => Comonad (ReactiveG t) instance (Monoid t) => Copointed (ReactiveG t) instance (Ord t) => Pointed (ReactiveG t) instance (Monoid t) => Comonad (EventG t) instance (Monoid t) => Copointed (EventG t) instance Unzip (EventG t) instance (Ord t, Cozip f) => Zip (EventG t :. f) instance (Ord t) => Monoid_f (EventG t :. f) instance (Ord t) => Monoid ((:.) (EventG t) f a) instance (Ord t) => Monoid_f (EventG t) instance Unzip (ReactiveG t) instance (Ord t, Zip f) => Zip (ReactiveG t :. f) instance (Monoid_f f, Ord t) => Monoid_f (ReactiveG t :. f) instance (Ord t) => Monad (ReactiveG t) instance (Ord t) => MonadPlus (EventG t) instance (Ord t) => Monad (EventG t) instance (Ord t) => Applicative (ReactiveG t) instance (Ord t) => Zip (ReactiveG t) instance (Ord t) => Alternative (EventG t) instance (Ord t) => Applicative (EventG t) instance Functor (ReactiveG t) instance Functor (EventG t) instance (Ord t, Monoid a) => Monoid (ReactiveG t a) instance (Ord t) => Monoid (EventG t a) instance (Ord t, Arbitrary t, Show t, EqProp a) => EqProp (ReactiveG t a) instance (Ord t) => Model (ReactiveG t a) (t -> a) instance (Arbitrary t, Arbitrary a, Num t, Ord t) => Arbitrary (ReactiveG t a) instance (Arbitrary t, Ord t, Num t, Arbitrary a) => Arbitrary (EventG t a) instance (Eq a, Eq b, EqProp a, EqProp b) => EqProp (EventG a b) -- | Simple reactive values. Adds some extra functionality on top of -- FRP.Reactive.PrimReactive module FRP.Reactive.Reactive -- | The type of finite time values. type TimeT = Double -- | Improving doubles, as used for time values in Event, -- Reactive, and ReactiveB. type ITime = Improving TimeT -- | Type of future values. Specializes FutureG. type Future = FutureG ITime -- | Trace the elements of a functor type. traceF :: (Functor f) => (a -> String) -> f a -> f a -- | Events, specialized to improving doubles for time type Event = EventG ITime -- | Access occurrence times in an event. See withTimeGE for more -- general notions of time. -- --
--   withTimeE :: Event a -> Event (a, TimeT)
--   
withTimeE :: (Ord t) => EventG (Improving t) d -> EventG (Improving t) (d, t) -- | Access occurrence times in an event. Discard the rest. See also -- withTimeE. -- --
--   withTimeE_ :: Event a -> Event TimeT
--   
withTimeE_ :: (Ord t) => EventG (Improving t) d -> EventG (Improving t) t -- | Single-occurrence event at given time. See atTimes and -- atTimeG. atTime :: TimeT -> Event () -- | Event occuring at given times. See also atTime and -- atTimeG. atTimes :: [TimeT] -> Event () -- | Convert a temporally monotonic list of timed values to an event. See -- also the generalization listEG listE :: [(TimeT, a)] -> Event a -- | Generate a pair-valued event, given a pair of initial values and a -- pair of events. See also pair on Reactive. Not quite a -- zip, because of the initial pair required. zipE :: (Ord t) => (c, d) -> (EventG t c, EventG t d) -> EventG t (c, d) -- | Like scanl for events. scanlE :: (Ord t) => (a -> b -> a) -> a -> EventG t b -> EventG t a -- | Accumulate values from a monoid-typed event. Specialization of -- scanlE, using mappend and mempty. monoidE :: (Ord t, Monoid o) => EventG t o -> EventG t o -- | Decompose an event into its first occurrence value and a remainder -- event. See also firstE and restE. firstRestE :: (Ord t) => EventG t a -> (a, EventG t a) -- | Extract the first occurrence value of an event. See also -- firstRestE and restE. firstE :: (Ord t) => EventG t a -> a -- | Extract the remainder an event, after its first occurrence. See also -- firstRestE and firstE. restE :: (Ord t) => EventG t a -> EventG t a -- | Remaining part of an event. See also withRestE. remainderR :: (Ord t) => EventG t a -> ReactiveG t (EventG t a) -- | Tack remainders a second event onto values of a first event. Occurs -- when the first event occurs. snapRemainderE :: Event a -> Event b -> Event (a, Event b) -- | Convert an event into a single-occurrence event, whose occurrence -- contains the remainder. onceRestE :: (Ord t) => EventG t a -> EventG t (a, EventG t a) -- | Pair each event value with the previous one. The second result is the -- old one. Nothing will come out for the first occurrence of e, -- but if you have an initial value a, you can do withPrevE -- (pure a mappend e). withPrevE :: (Ord t) => EventG t a -> EventG t (a, a) -- | Same as withPrevE, but allow a function to combine the values. -- Provided for convenience. withPrevEWith :: (Ord t) => (a -> a -> b) -> EventG t a -> EventG t b -- | Pair each event value with the next one one. The second result is the -- next one. withNextE :: (Ord t) => EventG t a -> EventG t (a, a) -- | Same as withNextE, but allow a function to combine the values. -- Provided for convenience. withNextEWith :: (Ord t) => (a -> a -> b) -> EventG t a -> EventG t b -- | Mealy-style state machine, given initial value and transition -- function. Carries along event data. See also mealy_. mealy :: (Ord t) => s -> (s -> s) -> EventG t b -> EventG t (b, s) -- | Mealy-style state machine, given initial value and transition -- function. Forgetful version of mealy. mealy_ :: (Ord t) => s -> (s -> s) -> EventG t b -> EventG t s -- | Count occurrences of an event, remembering the occurrence values. See -- also countE_. countE :: (Ord t, Num n) => EventG t b -> EventG t (b, n) -- | Count occurrences of an event, forgetting the occurrence values. See -- also countE. countE_ :: (Ord t, Num n) => EventG t b -> EventG t n -- | Difference of successive event occurrences. See withPrevE for a -- trick to supply an initial previous value. diffE :: (Ord t, Num n) => EventG t n -> EventG t n -- | Reactive values, specialized to improving doubles for time type Reactive = ReactiveG ITime -- | Like snapshot but discarding event data (often a is -- '()'). snapshot_ :: (Ord t) => EventG t a -> ReactiveG t b -> EventG t b -- | Snapshot a reactive value whenever an event occurs. snapshot :: (Ord t) => EventG t a -> ReactiveG t b -> EventG t (a, b) -- | Filter an event according to whether a reactive boolean is true. whenE :: (Ord t) => EventG t a -> ReactiveG t Bool -> EventG t a -- | Like scanl for reactive values. See also scanlE. scanlR :: (Ord t) => (a -> b -> a) -> a -> EventG t b -> ReactiveG t a -- | Accumulate values from a monoid-valued event. Specialization of -- scanlE, using mappend and mempty. See also -- monoidE. monoidR :: (Ord t, Monoid a) => EventG t a -> ReactiveG t a -- | Combine two events into one. eitherE :: (Ord t) => EventG t a -> EventG t b -> EventG t (Either a b) -- | Start out blank (Nothing), latching onto each new a, -- and blanking on each b. If you just want to latch and not -- blank, then use mempty for lose. maybeR :: (Ord t) => EventG t a -> EventG t b -> ReactiveG t (Maybe a) -- | Flip-flopping reactive value. Turns true when ea occurs and -- false when eb occurs. flipFlop :: (Ord t) => EventG t a -> EventG t b -> ReactiveG t Bool -- | Count occurrences of an event. See also countE. countR :: (Ord t, Num n) => EventG t a -> ReactiveG t n -- | Partition an event into segments. splitE :: (Ord t) => EventG t a -> EventG t b -> EventG t (a, EventG t b) -- | Switch from one event to another, as they occur. (Doesn't merge, as -- join does.) switchE :: (Ord t) => EventG t (EventG t a) -> EventG t a -- | Euler integral. integral :: (VectorSpace v, t ~ (Scalar v), Num t) => t -> Event t -> Reactive v -> Reactive v sumR :: (Ord t) => (AdditiveGroup v) => EventG t v -> ReactiveG t v exact :: Improving a -> a batch :: TestBatch -- | Representation of reactive behaviors module FRP.Reactive.Internal.Behavior -- | Reactive behaviors. They can be understood in terms of a simple model -- (denotational semantics) as functions of time, namely at :: -- BehaviorG t a -> (t -> a). -- -- The semantics of BehaviorG instances are given by corresponding -- instances for the semantic model (functions). See -- http://conal.net/blog/posts/simplifying-semantics-with-type-class-morphisms/. -- -- newtype BehaviorG tr tf a Beh :: (ReactiveG tr :. Fun tf) a -> BehaviorG tr tf a unBeh :: BehaviorG tr tf a -> (ReactiveG tr :. Fun tf) a -- | Wrap a reactive time fun as a behavior. beh :: ReactiveG tr (Fun tf a) -> BehaviorG tr tf a -- | Unwrap a behavior. unb :: BehaviorG tr tf a -> ReactiveG tr (Fun tf a) instance (Ord tr, Monoid a) => Monoid (BehaviorG tr tf a) instance Functor (BehaviorG tr tf) instance (Ord tr) => Applicative (BehaviorG tr tf) instance Unzip (BehaviorG tr tf) instance (Ord tr) => Zip (BehaviorG tr tf) instance (Applicative (ReactiveG tr :. Fun tf), Monoid a) => Monoid ((:.) (ReactiveG tr) (Fun tf) a) -- | Reactive behaviors (continuous time) module FRP.Reactive.Behavior -- | Reactive behaviors. They can be understood in terms of a simple model -- (denotational semantics) as functions of time, namely at :: -- BehaviorG t a -> (t -> a). -- -- The semantics of BehaviorG instances are given by corresponding -- instances for the semantic model (functions). See -- http://conal.net/blog/posts/simplifying-semantics-with-type-class-morphisms/. -- -- data BehaviorG tr tf a -- | Time-specialized behaviors. Note: The signatures of all of the -- behavior functions can be generalized. Is the interface generality -- worth the complexity? type Behavior = BehaviorI TimeT type Behaviour = Behavior -- | The identity generalized behavior. Has value t at time -- t. -- --
--   time :: Behavior TimeT
--   
time :: (Ord t) => BehaviorI t t -- | Discretely changing behavior, based on an initial value and a -- new-value event. -- --
--   stepper :: a -> Event a -> Behavior a
--   
stepper :: a -> EventI t a -> BehaviorI t a -- | Switch between behaviors. -- --
--   switcher :: Behavior a -> Event (Behavior a) -> Behavior a
--   
switcher :: (Ord tr) => BehaviorG tr tf a -> EventG tr (BehaviorG tr tf a) -> BehaviorG tr tf a -- | Snapshots a behavior whenever an event occurs and combines the values -- using the combining function passed. -- --
--   snapshotWith :: (a -> b -> c) -> Event a -> Behavior b -> Event c
--   
snapshotWith :: (Ord t) => (a -> b -> c) -> EventI t a -> BehaviorI t b -> EventI t c -- | Snapshot a behavior whenever an event occurs. See also -- snapshotWith. -- --
--   snapshot :: Event a -> Behavior b -> Event (a,b)
--   
snapshot :: (Ord t) => EventI t a -> BehaviorI t b -> EventI t (a, b) -- | Like snapshot but discarding event data (often a is -- '()'). -- --
--   snapshot_ :: Event a -> Behavior b -> Event b
--   
snapshot_ :: (Ord t) => EventI t a -> BehaviorI t b -> EventI t b -- | Filter an event according to whether a reactive boolean is true. -- --
--   whenE :: Event a -> Behavior Bool -> Event a
--   
whenE :: (Ord t) => EventI t a -> BehaviorI t Bool -> EventI t a -- | Behavior from an initial value and an updater event. See also accumE. -- --
--   accumB :: a -> Event (a -> a) -> Behavior a
--   
accumB :: a -> EventI t (a -> a) -> BehaviorI t a -- | Like scanl for behaviors. See also scanlE. -- --
--   scanlB :: forall a. (Behavior a -> Behavior a -> Behavior a) -> Behavior a
--          -> Event (Behavior a) -> Behavior a
--   
scanlB :: (Ord tr) => (b -> BehaviorG tr tf a -> BehaviorG tr tf a) -> BehaviorG tr tf a -> EventG tr b -> BehaviorG tr tf a -- | Accumulate values from a monoid-valued event. Specialization of -- scanlB, using mappend and mempty. See also -- monoidE. -- --
--   monoidB :: Monoid a => Event (Behavior a) -> Behavior a
--   
monoidB :: (Ord tr, Monoid a) => EventG tr (BehaviorG tr tf a) -> BehaviorG tr tf a -- | Start out blank (Nothing), latching onto each new a, -- and blanking on each b. If you just want to latch and not -- blank, then use mempty for the second event. -- --
--   maybeB :: Event a -> Event b -> Behavior (Maybe a)
--   
maybeB :: (Ord t) => EventI t a -> EventI t b -> BehaviorI t (Maybe a) -- | Flip-flopping behavior. Turns true whenever first event occurs and -- false whenever the second event occurs. -- --
--   flipFlop :: Event a -> Event b -> Behavior Bool
--   
flipFlop :: (Ord t) => EventI t a -> EventI t b -> BehaviorI t Bool -- | Count occurrences of an event. See also countE. -- --
--   countB :: Num n => Event a -> Behavior n
--   
countB :: (Ord t, Num n) => EventI t a -> BehaviorI t n -- | Like sum for behaviors. -- --
--   sumB :: AdditiveGroup a => Event a -> Behavior a
--   
sumB :: (Ord t, AdditiveGroup a) => EventI t a -> BehaviorI t a -- | Euler integral. -- --
--   integral :: (VectorSpace v, Scalar v ~ TimeT) =>
--               Event () -> Behavior v -> Behavior v
--   
integral :: ((Scalar v) ~ t, Ord t, VectorSpace v, Num t) => EventI t a -> BehaviorI t v -> BehaviorI t v instance (Monoid tr, Monoid tf) => Copointed (BehaviorG tr tf) instance (Functor g, Functor f, Copointed g, Copointed f) => Copointed (g :. f) -- | Numeric class instances for behaviors module FRP.Reactive.Num instance (RealFloat a) => RealFloat (Behavior a) instance (RealFrac a) => RealFrac (Behavior a) instance (Floating b) => Floating (Behavior b) instance (Fractional b) => Fractional (Behavior b) instance (Integral a) => Integral (Behavior a) instance (Num a, Ord a) => Real (Behavior a) instance (Num b) => Num (Behavior b) instance Show (Behavior b) instance (Enum a) => Enum (Behavior a) instance (Ord b) => Ord (Behavior b) instance Eq (Behavior b) module FRP.Reactive.VectorSpace instance (VectorSpace v) => VectorSpace (Behavior v) instance (AdditiveGroup v) => AdditiveGroup (Behavior v) -- | Serializing clocks -- -- Thanks to Luke Palmer for help with this module. module FRP.Reactive.Internal.Clock -- | Waits a specified duration and then execute an action type Delay t = t -- -> forall a. IO a -> IO a -- -- Waits until just after a specified time and then execute an action, -- passing in the actual time. type Schedule t = t -> Sink (Sink t) -- -- A serializing clock. Can (a) produce a time and (b) serialize an -- action. data Clock t Clock :: IO t -> Serial -> Clock t cGetTime :: Clock t -> IO t cSerialize :: Clock t -> Serial -- | Make a clock makeClock :: IO (Clock TimeT) module FRP.Reactive.Internal.Timing -- | Execute an action-valued event. adaptE :: Sink (Event Action) -- | Make an action to be executed regularly, given a time-source and a -- action-behavior. The generated action is optimized to do almost no -- work during known-constant phases of the given behavior. mkUpdater :: IO TimeT -> Behavior Action -> IO Action -- | Sleep past a given time sleepPast :: IO TimeT -> Sink TimeT -- | Timed values. A primitive interface for futures. module FRP.Reactive.Internal.TVal -- | Make a new event and a sink that writes to it. Uses the given clock to -- serialize and time-stamp. makeEvent :: Clock TimeT -> MkFed (Event a) a -- | An a that's fed by a b type Fed a b = (a, Sink b) -- | Make a Fed. type MkFed a b = IO (Fed a b) -- | Tools for making Reactive adapters for imperative ("legacy") -- libraries. module FRP.Reactive.LegacyAdapters -- | Value consumer type Sink a = a -> Action -- | Convenient alias for dropping parentheses. type Action = IO () -- | Waits a specified duration and then execute an action type Delay t = t -- -> forall a. IO a -> IO a -- -- Waits until just after a specified time and then execute an action, -- passing in the actual time. type Schedule t = t -> Sink (Sink t) -- -- A serializing clock. Can (a) produce a time and (b) serialize an -- action. data Clock t -- | Make a clock makeClock :: IO (Clock TimeT) cGetTime :: Clock t -> IO t -- | Execute an action-valued event. adaptE :: Sink (Event Action) -- | Make a new event and a sink that writes to it. Uses the given clock to -- serialize and time-stamp. makeEvent :: Clock TimeT -> MkFed (Event a) a -- | Make an action to be executed regularly, given a time-source and a -- action-behavior. The generated action is optimized to do almost no -- work during known-constant phases of the given behavior. mkUpdater :: IO TimeT -> Behavior Action -> IO Action -- | A library for programming with functional reactive behaviors. module FRP.Reactive -- | The type of finite time values. type TimeT = Double -- | Improving doubles, as used for time values in Event, -- Reactive, and ReactiveB. type ITime = Improving TimeT -- | Events. Semantically: time-ordered list of future values. Instances: -- -- data EventG t a -- | Events, specialized to improving doubles for time type Event = EventG ITime -- | Accumulating event, starting from an initial value and a -- update-function event. See also accumR. accumE :: a -> EventG t (a -> a) -> EventG t a -- | Access occurrence times in an event. See withTimeGE for more -- general notions of time. -- --
--   withTimeE :: Event a -> Event (a, TimeT)
--   
withTimeE :: (Ord t) => EventG (Improving t) d -> EventG (Improving t) (d, t) -- | Access occurrence times in an event. Discard the rest. See also -- withTimeE. -- --
--   withTimeE_ :: Event a -> Event TimeT
--   
withTimeE_ :: (Ord t) => EventG (Improving t) d -> EventG (Improving t) t -- | Generate a pair-valued event, given a pair of initial values and a -- pair of events. See also pair on Reactive. Not quite a -- zip, because of the initial pair required. zipE :: (Ord t) => (c, d) -> (EventG t c, EventG t d) -> EventG t (c, d) -- | Like scanl for events. scanlE :: (Ord t) => (a -> b -> a) -> a -> EventG t b -> EventG t a -- | Accumulate values from a monoid-typed event. Specialization of -- scanlE, using mappend and mempty. monoidE :: (Ord t, Monoid o) => EventG t o -> EventG t o -- | Mealy-style state machine, given initial value and transition -- function. Carries along event data. See also mealy_. mealy :: (Ord t) => s -> (s -> s) -> EventG t b -> EventG t (b, s) -- | Mealy-style state machine, given initial value and transition -- function. Forgetful version of mealy. mealy_ :: (Ord t) => s -> (s -> s) -> EventG t b -> EventG t s -- | Count occurrences of an event, remembering the occurrence values. See -- also countE_. countE :: (Ord t, Num n) => EventG t b -> EventG t (b, n) -- | Count occurrences of an event, forgetting the occurrence values. See -- also countE. countE_ :: (Ord t, Num n) => EventG t b -> EventG t n -- | Difference of successive event occurrences. See withPrevE for a -- trick to supply an initial previous value. diffE :: (Ord t, Num n) => EventG t n -> EventG t n -- | Pair each event value with the previous one. The second result is the -- old one. Nothing will come out for the first occurrence of e, -- but if you have an initial value a, you can do withPrevE -- (pure a mappend e). withPrevE :: (Ord t) => EventG t a -> EventG t (a, a) -- | Same as withPrevE, but allow a function to combine the values. -- Provided for convenience. withPrevEWith :: (Ord t) => (a -> a -> b) -> EventG t a -> EventG t b -- | Combine two events into one. eitherE :: (Ord t) => EventG t a -> EventG t b -> EventG t (Either a b) -- | Convert a temporally monotonic list of timed values to an event. See -- also the generalization listEG listE :: [(TimeT, a)] -> Event a -- | Event occuring at given times. See also atTime and -- atTimeG. atTimes :: [TimeT] -> Event () -- | Single-occurrence event at given time. See atTimes and -- atTimeG. atTime :: TimeT -> Event () -- | Just the first occurrence of an event. once :: (Ord t) => EventG t a -> EventG t a -- | Decompose an event into its first occurrence value and a remainder -- event. See also firstE and restE. firstRestE :: (Ord t) => EventG t a -> (a, EventG t a) -- | Extract the first occurrence value of an event. See also -- firstRestE and restE. firstE :: (Ord t) => EventG t a -> a -- | Extract the remainder an event, after its first occurrence. See also -- firstRestE and firstE. restE :: (Ord t) => EventG t a -> EventG t a -- | Tack remainders a second event onto values of a first event. Occurs -- when the first event occurs. snapRemainderE :: Event a -> Event b -> Event (a, Event b) -- | Access the remainder with each event occurrence. withRestE :: EventG t a -> EventG t (a, EventG t a) -- | Truncate first event at first occurrence of second event. untilE :: (Ord t) => EventG t a -> EventG t b -> EventG t a -- | Partition an event into segments. splitE :: (Ord t) => EventG t a -> EventG t b -> EventG t (a, EventG t b) -- | Switch from one event to another, as they occur. (Doesn't merge, as -- join does.) switchE :: (Ord t) => EventG t (EventG t a) -> EventG t a -- | Pass through the Just occurrences, stripped. Experimental -- specialization of joinMaybes. justE :: (Ord t) => EventG t (Maybe a) -> EventG t a -- | Pass through values satisfying a given predicate. Experimental -- specialization of filterMP. filterE :: (Ord t, Show a) => (a -> Bool) -> EventG t a -> EventG t a -- | Pass through Just occurrences. joinMaybes :: (MonadPlus m) => m (Maybe a) -> m a -- | Pass through values satisfying p. filterMP :: (MonadPlus m) => (a -> Bool) -> m a -> m a -- | Reactive behaviors. They can be understood in terms of a simple model -- (denotational semantics) as functions of time, namely at :: -- BehaviorG t a -> (t -> a). -- -- The semantics of BehaviorG instances are given by corresponding -- instances for the semantic model (functions). See -- http://conal.net/blog/posts/simplifying-semantics-with-type-class-morphisms/. -- -- data BehaviorG tr tf a -- | Time-specialized behaviors. Note: The signatures of all of the -- behavior functions can be generalized. Is the interface generality -- worth the complexity? type Behavior = BehaviorI TimeT type Behaviour = Behavior -- | The identity generalized behavior. Has value t at time -- t. -- --
--   time :: Behavior TimeT
--   
time :: (Ord t) => BehaviorI t t -- | Discretely changing behavior, based on an initial value and a -- new-value event. -- --
--   stepper :: a -> Event a -> Behavior a
--   
stepper :: a -> EventI t a -> BehaviorI t a -- | Switch between behaviors. -- --
--   switcher :: Behavior a -> Event (Behavior a) -> Behavior a
--   
switcher :: (Ord tr) => BehaviorG tr tf a -> EventG tr (BehaviorG tr tf a) -> BehaviorG tr tf a -- | Snapshots a behavior whenever an event occurs and combines the values -- using the combining function passed. -- --
--   snapshotWith :: (a -> b -> c) -> Event a -> Behavior b -> Event c
--   
snapshotWith :: (Ord t) => (a -> b -> c) -> EventI t a -> BehaviorI t b -> EventI t c -- | Snapshot a behavior whenever an event occurs. See also -- snapshotWith. -- --
--   snapshot :: Event a -> Behavior b -> Event (a,b)
--   
snapshot :: (Ord t) => EventI t a -> BehaviorI t b -> EventI t (a, b) -- | Like snapshot but discarding event data (often a is -- '()'). -- --
--   snapshot_ :: Event a -> Behavior b -> Event b
--   
snapshot_ :: (Ord t) => EventI t a -> BehaviorI t b -> EventI t b -- | Filter an event according to whether a reactive boolean is true. -- --
--   whenE :: Event a -> Behavior Bool -> Event a
--   
whenE :: (Ord t) => EventI t a -> BehaviorI t Bool -> EventI t a -- | Behavior from an initial value and an updater event. See also accumE. -- --
--   accumB :: a -> Event (a -> a) -> Behavior a
--   
accumB :: a -> EventI t (a -> a) -> BehaviorI t a -- | Like scanl for behaviors. See also scanlE. -- --
--   scanlB :: forall a. (Behavior a -> Behavior a -> Behavior a) -> Behavior a
--          -> Event (Behavior a) -> Behavior a
--   
scanlB :: (Ord tr) => (b -> BehaviorG tr tf a -> BehaviorG tr tf a) -> BehaviorG tr tf a -> EventG tr b -> BehaviorG tr tf a -- | Accumulate values from a monoid-valued event. Specialization of -- scanlB, using mappend and mempty. See also -- monoidE. -- --
--   monoidB :: Monoid a => Event (Behavior a) -> Behavior a
--   
monoidB :: (Ord tr, Monoid a) => EventG tr (BehaviorG tr tf a) -> BehaviorG tr tf a -- | Start out blank (Nothing), latching onto each new a, -- and blanking on each b. If you just want to latch and not -- blank, then use mempty for the second event. -- --
--   maybeB :: Event a -> Event b -> Behavior (Maybe a)
--   
maybeB :: (Ord t) => EventI t a -> EventI t b -> BehaviorI t (Maybe a) -- | Flip-flopping behavior. Turns true whenever first event occurs and -- false whenever the second event occurs. -- --
--   flipFlop :: Event a -> Event b -> Behavior Bool
--   
flipFlop :: (Ord t) => EventI t a -> EventI t b -> BehaviorI t Bool -- | Count occurrences of an event. See also countE. -- --
--   countB :: Num n => Event a -> Behavior n
--   
countB :: (Ord t, Num n) => EventI t a -> BehaviorI t n -- | Like sum for behaviors. -- --
--   sumB :: AdditiveGroup a => Event a -> Behavior a
--   
sumB :: (Ord t, AdditiveGroup a) => EventI t a -> BehaviorI t a -- | Euler integral. -- --
--   integral :: (VectorSpace v, Scalar v ~ TimeT) =>
--               Event () -> Behavior v -> Behavior v
--   
integral :: ((Scalar v) ~ t, Ord t, VectorSpace v, Num t) => EventI t a -> BehaviorI t v -> BehaviorI t v