{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Control.Natural.Control where
import Data.Coerce
import Data.Functor.Compose
import Data.Functor.Identity
data ControlTransformation st m n = ControlTransformation
{
forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n
-> forall a. ((forall x. n x -> Compose m st x) -> m a) -> n a
transWith :: !(forall a. ((forall x. n x -> Compose m st x) -> m a) -> n a),
forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n -> forall a. st a -> n a
restoreState :: !(forall a. st a -> n a)
}
toNatural :: ControlTransformation st m n -> (forall x. m x -> n x)
toNatural :: forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n -> forall x. m x -> n x
toNatural ControlTransformation st m n
ct m x
mx = forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n
-> forall a. ((forall x. n x -> Compose m st x) -> m a) -> n a
transWith ControlTransformation st m n
ct forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const m x
mx
type StatelessControlTransformation = ControlTransformation Identity
statelessControlTransformation ::
forall m n.
(Functor m, Applicative n) =>
(forall a. ((forall x. n x -> m x) -> m a) -> n a) ->
StatelessControlTransformation m n
statelessControlTransformation :: forall (m :: * -> *) (n :: * -> *).
(Functor m, Applicative n) =>
(forall a. ((forall x. n x -> m x) -> m a) -> n a)
-> StatelessControlTransformation m n
statelessControlTransformation forall a. ((forall x. n x -> m x) -> m a) -> n a
transWith' = ControlTransformation {forall a. Identity a -> n a
forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
restoreState :: forall a. Identity a -> n a
transWith :: forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
restoreState :: forall a. Identity a -> n a
transWith :: forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
..}
where
transWith :: forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
transWith :: forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
transWith (forall x. n x -> Compose m Identity x) -> m a
useRunInM = forall a. ((forall x. n x -> m x) -> m a) -> n a
transWith' forall a b. (a -> b) -> a -> b
$ \forall x. n x -> m x
runInM -> (forall x. n x -> Compose m Identity x) -> m a
useRunInM (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. n x -> m x
runInM)
restoreState :: forall a. Identity a -> n a
restoreState :: forall a. Identity a -> n a
restoreState = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. coerce :: forall a b. Coercible a b => a -> b
coerce
statelessTransWith ::
(Functor m) =>
StatelessControlTransformation m n ->
(((forall x. n x -> m x) -> m a) -> n a)
statelessTransWith :: forall (m :: * -> *) (n :: * -> *) a.
Functor m =>
StatelessControlTransformation m n
-> ((forall x. n x -> m x) -> m a) -> n a
statelessTransWith (ControlTransformation {forall a. Identity a -> n a
forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
restoreState :: forall a. Identity a -> n a
transWith :: forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
restoreState :: forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n -> forall a. st a -> n a
transWith :: forall (st :: * -> *) (m :: * -> *) (n :: * -> *).
ControlTransformation st m n
-> forall a. ((forall x. n x -> Compose m st x) -> m a) -> n a
..}) (forall x. n x -> m x) -> m a
useRunInM = forall a. ((forall x. n x -> Compose m Identity x) -> m a) -> n a
transWith forall a b. (a -> b) -> a -> b
$ \forall x. n x -> Compose m Identity x
runInM -> (forall x. n x -> m x) -> m a
useRunInM (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. n x -> Compose m Identity x
runInM)