packages feed

reactive 0.9.9 → 0.9.10

raw patch · 5 files changed

+63/−20 lines, 5 files

Files

reactive.cabal view
@@ -1,5 +1,5 @@ Name:                reactive-Version:             0.9.9+Version:             0.9.10 Synopsis:            Simple foundation for functional reactive programming Category:            reactivity, FRP Description:
src/Data/AddBounds.hs view
@@ -15,6 +15,8 @@  import Control.Applicative (pure,(<$>)) +-- import Data.Unamb (unamb)+ -- Testing import Test.QuickCheck import Test.QuickCheck.Checkers@@ -61,6 +63,42 @@   NoBound a `max` NoBound b = NoBound (a `max` b)   _         `max` MaxBound  = MaxBound   MaxBound  `max` _         = MaxBound+++-- Richard Smith (lilac)  contributed this code for lazier methods.+--   MaxBound `max` undefined can return full information while the default+--   implementation cannot. And likewise undefined `max` MaxBound.++-- instance Ord a => Ord (AddBounds a) where+--   a <= b = c1 a b `unamb` c2 a b+--     where c1 MinBound     _            = True+--           c1 _            MinBound     = False+--           c1 (NoBound a') (NoBound b') = a' < b'+--           c1 MaxBound     (NoBound _)  = False+--           c1 _            _            = undefined+--           c2 _            MaxBound     = True+--           c2 _            _            = undefined+--   a `min` b = c1 a b `unamb` c2 a b+--     where c1 MinBound     _            = MinBound+--           c1 (NoBound a') (NoBound b') = NoBound $ a' `max` b'+--           c1 (NoBound _ ) MaxBound     = a+--           c1 MaxBound     (NoBound _ ) = b+--           c1 MaxBound     MaxBound     = MaxBound+--           c1 _            _            = undefined+--           c2 _            MinBound     = MinBound+--           c2 _            _            = undefined+--   a `max` b = c1 a b `unamb` c2 a b+--     where c1 MaxBound     _            = MaxBound+--           c1 (NoBound a') (NoBound b') = NoBound $ a' `max` b'+--           c1 (NoBound _ ) MinBound     = a+--           c1 MinBound     (NoBound _ ) = b+--           c1 MinBound     MinBound     = MinBound+--           c1 _            _            = undefined+--           c2 _            MaxBound     = MaxBound+--           c2 _            _            = undefined++-- This second instance has a strange delays in a reactive-fieldtrip+-- program.  My mouse click isn't responded to until I move the mouse.   instance Arbitrary a => Arbitrary (AddBounds a) where
src/FRP/Reactive/Behavior.hs view
@@ -101,8 +101,8 @@ -- > 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-snapshotWith h e b = f <$> (withTimeE e `R.snapshot` unb b)+             -> BehaviorI t b -> EventI t a -> EventI t c+snapshotWith h b e = f <$> (unb b `R.snapshot` withTimeE e)  where    f ((a,t),tfun) = h a (tfun `apply` t) @@ -117,7 +117,7 @@ -- | 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)+snapshot :: Ord t => BehaviorI t b -> EventI t a -> EventI t (a,b) snapshot = snapshotWith (,)  -- TODO: tweak withTimeE so that 'snapshotWith' and 'snapshot' can have@@ -131,7 +131,7 @@ -- | 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+snapshot_ :: Ord t => BehaviorI t b -> EventI t a -> EventI t b snapshot_ = snapshotWith (flip const)  -- Alternative implementations@@ -142,7 +142,7 @@ --  -- > whenE :: Event a -> Behavior Bool -> Event a whenE :: Ord t => EventI t a -> BehaviorI t Bool -> EventI t a-whenE e = joinMaybes . fmap h . snapshot e+whenE e = joinMaybes . fmap h . flip snapshot e  where    h (a,True)  = Just a    h (_,False) = Nothing@@ -183,7 +183,7 @@ -- monoidB :: Monoid a => Event (Behavior a) -> Behavior a -- monoidB = scanlB mappend mempty --- -- I doubt these definitions work well.  They accumulate reactives without+-- -- I doubt the above definitions work well.  They accumulate reactives without -- -- aging them.  See 'accumE'.  @@ -248,7 +248,7 @@ -- >             Event () -> Behavior v -> Behavior v integral :: (Scalar v ~ t, Ord t, VectorSpace v, Num t) =>             EventI t a -> BehaviorI t v -> BehaviorI t v-integral t = sumB . snapshotWith (*^) (diffE (t `snapshot_` time))+integral t b = sumB (snapshotWith (*^) b (diffE (time `snapshot_` t)))  -- Yow!  That's a mouth full! 
src/FRP/Reactive/PrimReactive.hs view
@@ -438,9 +438,9 @@ -- This variant of 'snapshot' has 'Nothing's where @b@ changed and @a@ -- didn't. snap :: forall a b t. Ord t =>-        EventG t a -> ReactiveG t b -> EventG t (Maybe a, b)-Event (Future (Max MaxBound, _)) `snap` _ = mempty-ea `snap` (b0 `Stepper` eb) =+        ReactiveG t b -> EventG t a -> EventG t (Maybe a, b)+_ `snap` Event (Future (Max MaxBound, _)) = mempty+(b0 `Stepper` eb) `snap` ea =   (Nothing, b0) `accumE` (fmap fa ea `mappend` fmap fb eb)  where    fa :: a -> Unop (Maybe a, b)@@ -451,7 +451,7 @@ -- | 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+                (a -> b -> c) -> ReactiveG t b -> EventG t a -> EventG t c snapshotWith f e r = joinMaybes $ fmap h (e `snap` r)  where    h (Nothing,_) = Nothing
src/FRP/Reactive/Reactive.hs view
@@ -166,9 +166,14 @@  -- | 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)-snapRemainderE ea eb = ea `snapshot` remainderR eb+snapRemainderE :: Ord t =>+                  EventG t b -> EventG t a -> EventG t (a, EventG t b)+snapRemainderE = snapshot . remainderR +-- snapRemainderE eb = snapshot (remainderR eb)++-- eb `snapRemainderE` ea = remainderR eb `snapshot` ea+ -- withTailE ea eb = error "withTailE: undefined" ea eb  @@ -266,11 +271,11 @@   -- | Snapshot a reactive value whenever an event occurs.-snapshot :: Ord t => EventG t a -> ReactiveG t b -> EventG t (a,b)+snapshot :: Ord t => ReactiveG t b -> EventG t a -> EventG t (a,b) snapshot = snapshotWith (,)  -- | Like 'snapshot' but discarding event data (often @a@ is '()').-snapshot_ :: Ord t => EventG t a -> ReactiveG t b -> EventG t b+snapshot_ :: Ord t => ReactiveG t b -> EventG t a -> EventG t b snapshot_ = snapshotWith (flip const)  -- Alternative implementations@@ -279,7 +284,7 @@  -- | Filter an event according to whether a reactive boolean is true. whenE :: Ord t => EventG t a -> ReactiveG t Bool -> EventG t a-whenE e = joinMaybes . fmap h . snapshot e+whenE e = joinMaybes . fmap h . flip snapshot e  where    h (a,True)  = Just a    h (_,False) = Nothing@@ -320,8 +325,8 @@ countR e = 0 `stepper` countE_ e  -- | Partition an event into segments.-splitE :: Ord t => EventG t a -> EventG t b -> EventG t (a, EventG t b)-ea `splitE` eb = h <$> (withRestE ea `snapshot` remainderR eb)+splitE :: Ord t => EventG t b -> EventG t a -> EventG t (a, EventG t b)+eb `splitE` ea = h <$> (eb `snapRemainderE` withRestE ea)  where    h ((a,ea'),eb') = (a, eb' `untilE` ea') @@ -334,7 +339,7 @@ -- | Euler integral. integral :: forall v t. (VectorSpace v, t ~ Scalar v, Num t) =>             t -> Event t -> Reactive v -> Reactive v-integral t0 newT r = sumR (snapshotWith (*^) deltaT r)+integral t0 newT r = sumR (snapshotWith (*^) r deltaT)   where     deltaT :: Event t     deltaT = diffE (pure t0 `mappend` newT)