reactive 0.9.6 → 0.9.7
raw patch · 5 files changed
+64/−41 lines, 5 files
Files
- reactive.cabal +1/−1
- src/FRP/Reactive/Behavior.hs +32/−4
- src/FRP/Reactive/Fun.hs +26/−30
- src/FRP/Reactive/Internal/Clock.hs +2/−4
- src/FRP/Reactive/PrimReactive.hs +3/−2
reactive.cabal view
@@ -1,5 +1,5 @@ Name: reactive-Version: 0.9.6+Version: 0.9.7 Synopsis: Simple foundation for functional reactive programming Category: reactivity, FRP Description:
src/FRP/Reactive/Behavior.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ScopedTypeVariables, FlexibleContexts, TypeFamilies, TypeOperators , StandaloneDeriving, GeneralizedNewtypeDeriving+ , TypeSynonymInstances, UndecidableInstances #-} {-# OPTIONS_GHC -Wall -fno-warn-orphans #-} ----------------------------------------------------------------------@@ -267,8 +268,12 @@ instance (Functor g, Functor f, Copointed g, Copointed f) => Copointed (g :. f) where- extract = extract . fmap extract . unO+ extract = extract . extract . unO +-- instance (Comonad g, Comonad f) => Comonad (g :. f) where+-- duplicate = inO (fmap duplicate . duplicate)++ -- WORKING HERE -- The plan for duplicate:@@ -291,14 +296,37 @@ -- (+). This monoid change moves us from absolute to relative time. What -- do I do for never-occuring futures and terminating events? +-- --- instance (Monoid tr, Monoid tf) => Comonad (BehaviorI tf) where--- duplicate b = b `stepper` undefined+-- instance (Ord t, Monoid t, Monoid (Improving t)) => Comonad (BehaviorI t) where+-- duplicate = duplicateB +-- duplicateB :: forall t a.+-- (Ord t, Monoid t, Monoid (Improving t)) =>+-- BehaviorI t -> BehaviorI t (BehaviorI t a) where+-- duplicate b@(_ `Stepper`) = bb0 `switcher` +-- where+-- f0 `R.Stepper` e = unb b+-- bb0 = beh (pure (fun (\ t -> undefined))) --- TODO: generalize to BehaviorG+-- f0 :: T a +-- e :: E (T a) +-- duplicate f0 :: T (T a)+++-- b :: B a++-- unb b :: R (T a)++++-- dup b :: B (B a)+++-- TODO: generalize to BehaviorG+-- TODO: something about Monoid (Improving t) -- Standard instances for applicative functors
src/FRP/Reactive/Fun.hs view
@@ -9,18 +9,25 @@ -- Maintainer : conal@conal.net -- Stability : experimental -- --- Functions, with constant functions optimized. With instances of--- 'Functor', 'Applicative', 'Monad', and 'Arrow'+-- Functions, with constant functions optimized, with instances for many+-- standard classes. ---------------------------------------------------------------------- module FRP.Reactive.Fun (Fun, fun, apply, batch) where -import Data.Monoid (Monoid(..))-import Control.Applicative (Applicative(..),liftA)+import Prelude hiding+ ( zip, zipWith #if __GLASGOW_HASKELL__ >= 609+ , (.), id+#endif+ )+#if __GLASGOW_HASKELL__ >= 609 import Control.Category-import Prelude hiding ((.), id) #endif+++import Data.Monoid (Monoid(..))+import Control.Applicative (Applicative(..),liftA) import Control.Arrow #if __GLASGOW_HASKELL__ < 610 hiding (pure)@@ -29,6 +36,8 @@ import Control.Comonad +import Data.Zip (Zip(..))+ import Test.QuickCheck import Test.QuickCheck.Checkers import Test.QuickCheck.Classes@@ -71,10 +80,12 @@ instance Functor (Fun t) where fmap f (K a) = K (f a)- fmap f (Fun g) = Fun (f.g)- -- Or use- -- fmap f = (pure f <*>)+ fmap f (Fun g) = Fun (f.g) -- == Fun (fmap f g) +instance Zip (Fun t) where+ K x `zip` K y = K (x,y)+ cf `zip` cx = Fun (apply cf `zip` apply cx)+ instance Applicative (Fun t) where pure = K K f <*> K x = K (f x)@@ -122,33 +133,18 @@ batch :: TestBatch batch = ( "FRP.Reactive.Fun" , concatMap unbatch- [ monoid (undefined :: Fun NumT- [T])- , semanticMonoid (undefined :: Fun NumT- [T])- , functor (undefined :: Fun NumT- (NumT- ,T- ,NumT))+ [ monoid (undefined :: Fun NumT [T])+ , semanticMonoid (undefined :: Fun NumT [T])+ , functor (undefined :: Fun NumT (NumT,T,NumT)) , semanticFunctor (undefined :: Fun NumT ())- , applicative (undefined :: Fun NumT- (NumT- ,T- ,NumT))+ , applicative (undefined :: Fun NumT (NumT,T,NumT)) , semanticApplicative (undefined :: Fun NumT ())- , monad (undefined :: Fun NumT- (NumT- ,T- ,NumT))+ , monad (undefined :: Fun NumT (NumT,T,NumT)) , semanticMonad (undefined :: Fun NumT ())- , arrow (undefined :: Fun NumT- (NumT- ,T- ,NumT))+ , arrow (undefined :: Fun NumT (NumT,T,NumT)) , ("specifics", [("Constants are" ,property (\x -> (K (x :: NumT)) =-=- ((fun . const $ x) :: Fun T- NumT)))])+ ((fun . const $ x) :: Fun T NumT)))]) ] )
src/FRP/Reactive/Internal/Clock.hs view
@@ -38,9 +38,7 @@ , cSerialize :: Serial } --- | Make a clock, given a way to delay actions. For instance, the delay--- could be 'sleepThen' in thread-safe situations, but could also--- involve a GUI toolkit wake-up event.+-- | Make a clock makeClock :: IO (Clock TimeT) makeClock = liftA2 clock getClockTime makeSerial where@@ -49,7 +47,7 @@ Clock (currRelTime refTime) serial --- TODO: How can i know that actions are carried out monotonically?+-- TODO: How can I know that actions are carried out monotonically? -- | Get the current time in seconds, relative to a start 'ClockTime'. currRelTime :: ClockTime -> IO TimeT
src/FRP/Reactive/PrimReactive.hs view
@@ -58,7 +58,7 @@ , batch, infE ) where -import Prelude hiding (zip)+import Prelude hiding (zip,zipWith) import Data.Monoid import Control.Applicative@@ -204,7 +204,7 @@ instance Ord t => Applicative (ReactiveG t) where pure a = a `stepper` mempty -- Standard definition. See 'Zip'.- rf <*> rx = uncurry ($) <$> (rf `zip` rx)+ rf <*> rx = zipWith ($) rf rx -- A wonderful thing about the <*> definition for ReactiveG is that it -- automatically caches the previous value of the function or argument@@ -439,6 +439,7 @@ -- 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) = (Nothing, b0) `accumE` (fmap fa ea `mappend` fmap fb eb) where