{-# language CPP #-}
module Reactive.Banana.Types (
Event(..), Behavior(..),
Moment(..), MomentIO(..), MonadMoment(..),
Future(..),
) where
import Control.Applicative
import Control.Monad.IO.Class
import Control.Monad.Fix
import Data.String (IsString(..))
import Control.Monad.Trans.Accum (AccumT)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Identity (IdentityT)
import Control.Monad.Trans.Maybe (MaybeT)
import qualified Control.Monad.Trans.RWS.Lazy as Lazy (RWST)
import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST)
import Control.Monad.Trans.Reader (ReaderT)
import qualified Control.Monad.Trans.State.Lazy as Lazy (StateT)
import qualified Control.Monad.Trans.State.Strict as Strict (StateT)
import qualified Control.Monad.Trans.Writer.Lazy as Lazy (WriterT)
import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT)
#if MIN_VERSION_transformers(0,5,6)
import qualified Control.Monad.Trans.RWS.CPS as CPS (RWST)
import qualified Control.Monad.Trans.Writer.CPS as CPS (WriterT)
#endif
import qualified Reactive.Banana.Prim.High.Combinators as Prim
newtype Event a = E { forall a. Event a -> Event a
unE :: Prim.Event a }
instance Functor Event where
fmap :: forall a b. (a -> b) -> Event a -> Event b
fmap a -> b
f = forall a. Event a -> Event a
E forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> Event a -> Event b
Prim.mapE a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Event a -> Event a
unE
instance Semigroup a => Semigroup (Event a) where
Event a
x <> :: Event a -> Event a -> Event a
<> Event a
y = forall a. Event a -> Event a
E forall a b. (a -> b) -> a -> b
$ forall a c b.
(a -> c)
-> (b -> c) -> (a -> b -> c) -> Event a -> Event b -> Event c
Prim.mergeWith forall a. a -> a
id forall a. a -> a
id forall a. Semigroup a => a -> a -> a
(<>) (forall a. Event a -> Event a
unE Event a
x) (forall a. Event a -> Event a
unE Event a
y)
instance Semigroup a => Monoid (Event a) where
mempty :: Event a
mempty = forall a. Event a -> Event a
E forall a. Event a
Prim.never
mappend :: Event a -> Event a -> Event a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
newtype Behavior a = B { forall a. Behavior a -> Behavior a
unB :: Prim.Behavior a }
instance Applicative Behavior where
pure :: forall a. a -> Behavior a
pure a
x = forall a. Behavior a -> Behavior a
B forall a b. (a -> b) -> a -> b
$ forall a. a -> Behavior a
Prim.pureB a
x
Behavior (a -> b)
bf <*> :: forall a b. Behavior (a -> b) -> Behavior a -> Behavior b
<*> Behavior a
bx = forall a. Behavior a -> Behavior a
B forall a b. (a -> b) -> a -> b
$ forall a b. Behavior (a -> b) -> Behavior a -> Behavior b
Prim.applyB (forall a. Behavior a -> Behavior a
unB Behavior (a -> b)
bf) (forall a. Behavior a -> Behavior a
unB Behavior a
bx)
instance Functor Behavior where
fmap :: forall a b. (a -> b) -> Behavior a -> Behavior b
fmap = forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
liftA
instance Semigroup a => Semigroup (Behavior a) where
<> :: Behavior a -> Behavior a -> Behavior a
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>)
instance (Semigroup a, Monoid a) => Monoid (Behavior a) where
mempty :: Behavior a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
mappend :: Behavior a -> Behavior a -> Behavior a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance Num a => Num (Behavior a) where
+ :: Behavior a -> Behavior a -> Behavior a
(+) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(+)
(-) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
* :: Behavior a -> Behavior a -> Behavior a
(*) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(*)
abs :: Behavior a -> Behavior a
abs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
abs
signum :: Behavior a -> Behavior a
signum = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
signum
fromInteger :: Integer -> Behavior a
fromInteger = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger
negate :: Behavior a -> Behavior a
negate = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
negate
instance Fractional a => Fractional (Behavior a) where
/ :: Behavior a -> Behavior a -> Behavior a
(/) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Fractional a => a -> a -> a
(/)
fromRational :: Rational -> Behavior a
fromRational = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => Rational -> a
fromRational
recip :: Behavior a -> Behavior a
recip = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Fractional a => a -> a
recip
instance Floating a => Floating (Behavior a) where
** :: Behavior a -> Behavior a -> Behavior a
(**) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
(**)
acos :: Behavior a -> Behavior a
acos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acos
acosh :: Behavior a -> Behavior a
acosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acosh
asin :: Behavior a -> Behavior a
asin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asin
asinh :: Behavior a -> Behavior a
asinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asinh
atan :: Behavior a -> Behavior a
atan = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atan
atanh :: Behavior a -> Behavior a
atanh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atanh
cos :: Behavior a -> Behavior a
cos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cos
cosh :: Behavior a -> Behavior a
cosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cosh
exp :: Behavior a -> Behavior a
exp = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
exp
log :: Behavior a -> Behavior a
log = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
log
logBase :: Behavior a -> Behavior a -> Behavior a
logBase = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
logBase
pi :: Behavior a
pi = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Floating a => a
pi
sin :: Behavior a -> Behavior a
sin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sin
sinh :: Behavior a -> Behavior a
sinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sinh
sqrt :: Behavior a -> Behavior a
sqrt = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sqrt
instance IsString a => IsString (Behavior a) where
fromString :: String -> Behavior a
fromString = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
newtype Future a = F { forall a. Future a -> Future a
unF :: Prim.Future a }
instance Functor Future where fmap :: forall a b. (a -> b) -> Future a -> Future b
fmap a -> b
f = forall a. Future a -> Future a
F forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Future a -> Future a
unF
instance Monad Future where
Future a
m >>= :: forall a b. Future a -> (a -> Future b) -> Future b
>>= a -> Future b
g = forall a. Future a -> Future a
F forall a b. (a -> b) -> a -> b
$ forall a. Future a -> Future a
unF Future a
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. Future a -> Future a
unF forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Future b
g
instance Applicative Future where
pure :: forall a. a -> Future a
pure = forall a. Future a -> Future a
F forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
Future (a -> b)
f <*> :: forall a b. Future (a -> b) -> Future a -> Future b
<*> Future a
a = forall a. Future a -> Future a
F forall a b. (a -> b) -> a -> b
$ forall a. Future a -> Future a
unF Future (a -> b)
f forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Future a -> Future a
unF Future a
a
newtype Moment a = M { forall a. Moment a -> Moment a
unM :: Prim.Moment a }
newtype MomentIO a = MIO { forall a. MomentIO a -> Moment a
unMIO :: Prim.Moment a }
instance MonadIO MomentIO where liftIO :: forall a. IO a -> MomentIO a
liftIO = forall a. Moment a -> MomentIO a
MIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
class MonadFix m => MonadMoment m where
liftMoment :: Moment a -> m a
instance MonadMoment Moment where liftMoment :: forall a. Moment a -> Moment a
liftMoment = forall a. a -> a
id
instance MonadMoment MomentIO where liftMoment :: forall a. Moment a -> MomentIO a
liftMoment = forall a. Moment a -> MomentIO a
MIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Moment a -> Moment a
unM
instance (MonadMoment m, Monoid w) => MonadMoment (AccumT w m) where liftMoment :: forall a. Moment a -> AccumT w m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (ExceptT e m) where liftMoment :: forall a. Moment a -> ExceptT e m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (IdentityT m) where liftMoment :: forall a. Moment a -> IdentityT m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (MaybeT m) where liftMoment :: forall a. Moment a -> MaybeT m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance (MonadMoment m, Monoid w) => MonadMoment (Lazy.RWST r w s m) where liftMoment :: forall a. Moment a -> RWST r w s m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance (MonadMoment m, Monoid w) => MonadMoment (Strict.RWST r w s m) where liftMoment :: forall a. Moment a -> RWST r w s m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (ReaderT r m) where liftMoment :: forall a. Moment a -> ReaderT r m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (Lazy.StateT s m) where liftMoment :: forall a. Moment a -> StateT s m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (Strict.StateT s m) where liftMoment :: forall a. Moment a -> StateT s m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance (MonadMoment m, Monoid w) => MonadMoment (Lazy.WriterT w m) where liftMoment :: forall a. Moment a -> WriterT w m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance (MonadMoment m, Monoid w) => MonadMoment (Strict.WriterT w m) where liftMoment :: forall a. Moment a -> WriterT w m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
#if MIN_VERSION_transformers(0,5,6)
instance MonadMoment m => MonadMoment (CPS.RWST r w s m) where liftMoment :: forall a. Moment a -> RWST r w s m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
instance MonadMoment m => MonadMoment (CPS.WriterT w m) where liftMoment :: forall a. Moment a -> WriterT w m a
liftMoment = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadMoment m => Moment a -> m a
liftMoment
#endif
instance Functor Moment where fmap :: forall a b. (a -> b) -> Moment a -> Moment b
fmap a -> b
f = forall a. Moment a -> Moment a
M forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Moment a -> Moment a
unM
instance Monad Moment where
Moment a
m >>= :: forall a b. Moment a -> (a -> Moment b) -> Moment b
>>= a -> Moment b
g = forall a. Moment a -> Moment a
M forall a b. (a -> b) -> a -> b
$ forall a. Moment a -> Moment a
unM Moment a
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. Moment a -> Moment a
unM forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Moment b
g
instance Applicative Moment where
pure :: forall a. a -> Moment a
pure = forall a. Moment a -> Moment a
M forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
Moment (a -> b)
f <*> :: forall a b. Moment (a -> b) -> Moment a -> Moment b
<*> Moment a
a = forall a. Moment a -> Moment a
M forall a b. (a -> b) -> a -> b
$ forall a. Moment a -> Moment a
unM Moment (a -> b)
f forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Moment a -> Moment a
unM Moment a
a
instance MonadFix Moment where mfix :: forall a. (a -> Moment a) -> Moment a
mfix a -> Moment a
f = forall a. Moment a -> Moment a
M forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (forall a. Moment a -> Moment a
unM forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Moment a
f)
instance Semigroup a => Semigroup (Moment a) where
<> :: Moment a -> Moment a -> Moment a
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>)
instance Monoid a => Monoid (Moment a) where
mempty :: Moment a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
instance Functor MomentIO where fmap :: forall a b. (a -> b) -> MomentIO a -> MomentIO b
fmap a -> b
f = forall a. Moment a -> MomentIO a
MIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. MomentIO a -> Moment a
unMIO
instance Monad MomentIO where
MomentIO a
m >>= :: forall a b. MomentIO a -> (a -> MomentIO b) -> MomentIO b
>>= a -> MomentIO b
g = forall a. Moment a -> MomentIO a
MIO forall a b. (a -> b) -> a -> b
$ forall a. MomentIO a -> Moment a
unMIO MomentIO a
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. MomentIO a -> Moment a
unMIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> MomentIO b
g
instance Applicative MomentIO where
pure :: forall a. a -> MomentIO a
pure = forall a. Moment a -> MomentIO a
MIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure
MomentIO (a -> b)
f <*> :: forall a b. MomentIO (a -> b) -> MomentIO a -> MomentIO b
<*> MomentIO a
a = forall a. Moment a -> MomentIO a
MIO forall a b. (a -> b) -> a -> b
$ forall a. MomentIO a -> Moment a
unMIO MomentIO (a -> b)
f forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. MomentIO a -> Moment a
unMIO MomentIO a
a
instance MonadFix MomentIO where mfix :: forall a. (a -> MomentIO a) -> MomentIO a
mfix a -> MomentIO a
f = forall a. Moment a -> MomentIO a
MIO forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (forall a. MomentIO a -> Moment a
unMIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> MomentIO a
f)
instance Semigroup a => Semigroup (MomentIO a) where
<> :: MomentIO a -> MomentIO a -> MomentIO a
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>)
instance Monoid a => Monoid (MomentIO a) where
mempty :: MomentIO a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty