module Simulation.Aivika.Trans.Dynamics.Memo
(MonadMemo(..),
unzipDynamics,
unzip0Dynamics) where
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Trans.Internal.Simulation
import Simulation.Aivika.Trans.Internal.Dynamics
class Monad m => MonadMemo m where
memoDynamics :: Dynamics m e -> Simulation m (Dynamics m e)
memo0Dynamics :: Dynamics m e -> Simulation m (Dynamics m e)
iterateDynamics :: Dynamics m () -> Simulation m (Dynamics m ())
unzipDynamics :: MonadMemo m => Dynamics m (a, b) -> Simulation m (Dynamics m a, Dynamics m b)
{-# INLINABLE unzipDynamics #-}
unzipDynamics :: forall (m :: * -> *) a b.
MonadMemo m =>
Dynamics m (a, b) -> Simulation m (Dynamics m a, Dynamics m b)
unzipDynamics Dynamics m (a, b)
m =
forall (m :: * -> *) a. (Run m -> m a) -> Simulation m a
Simulation forall a b. (a -> b) -> a -> b
$ \Run m
r ->
do Dynamics m (a, b)
m' <- forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (forall (m :: * -> *) e.
MonadMemo m =>
Dynamics m e -> Simulation m (Dynamics m e)
memoDynamics Dynamics m (a, b)
m)
let ma :: Dynamics m a
ma =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do (a
a, b
_) <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m (a, b)
m'
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
mb :: Dynamics m b
mb =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do (a
_, b
b) <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m (a, b)
m'
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
forall (m :: * -> *) a. Monad m => a -> m a
return (Dynamics m a
ma, Dynamics m b
mb)
unzip0Dynamics :: MonadMemo m => Dynamics m (a, b) -> Simulation m (Dynamics m a, Dynamics m b)
{-# INLINABLE unzip0Dynamics #-}
unzip0Dynamics :: forall (m :: * -> *) a b.
MonadMemo m =>
Dynamics m (a, b) -> Simulation m (Dynamics m a, Dynamics m b)
unzip0Dynamics Dynamics m (a, b)
m =
forall (m :: * -> *) a. (Run m -> m a) -> Simulation m a
Simulation forall a b. (a -> b) -> a -> b
$ \Run m
r ->
do Dynamics m (a, b)
m' <- forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (forall (m :: * -> *) e.
MonadMemo m =>
Dynamics m e -> Simulation m (Dynamics m e)
memo0Dynamics Dynamics m (a, b)
m)
let ma :: Dynamics m a
ma =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do (a
a, b
_) <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m (a, b)
m'
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
mb :: Dynamics m b
mb =
forall (m :: * -> *) a. (Point m -> m a) -> Dynamics m a
Dynamics forall a b. (a -> b) -> a -> b
$ \Point m
p ->
do (a
_, b
b) <- forall (m :: * -> *) a. Point m -> Dynamics m a -> m a
invokeDynamics Point m
p Dynamics m (a, b)
m'
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
forall (m :: * -> *) a. Monad m => a -> m a
return (Dynamics m a
ma, Dynamics m b
mb)