module UVMHS.Core.Monads where
import UVMHS.Core.Init
import UVMHS.Core.Classes
import UVMHS.Core.Data
import UVMHS.Core.Effects
import UVMHS.Core.Transformers
import qualified Prelude as HS
newtype MU m = MU { forall (m :: * -> *). MU m -> m ()
unMU ∷ m () }
instance (Return m) ⇒ Null (MU m) where null :: MU m
null = m () -> MU m
forall (m :: * -> *). m () -> MU m
MU (m () -> MU m) -> m () -> MU m
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ()
instance (Bind m) ⇒ Append (MU m) where MU m
x ⧺ :: MU m -> MU m -> MU m
⧺ MU m
y = m () -> MU m
forall (m :: * -> *). m () -> MU m
MU (m () -> MU m) -> m () -> MU m
forall a b. (a -> b) -> a -> b
$ MU m -> m ()
forall (m :: * -> *). MU m -> m ()
unMU MU m
x m () -> m () -> m ()
forall (m :: * -> *) a b. Bind m => m a -> m b -> m b
≫ MU m -> m ()
forall (m :: * -> *). MU m -> m ()
unMU MU m
y
instance (Monad m) ⇒ Monoid (MU m)
instance MonadIO IO where
io :: forall a. IO a -> IO a
io = IO a -> IO a
forall a. a -> a
id
instance Functor IO where
map :: forall a b. (a -> b) -> IO a -> IO b
map = (a -> b) -> IO a -> IO b
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
mmap
instance Return IO where
return :: forall a. a -> IO a
return = a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
HS.return
instance Bind IO where
≫= :: forall a b. IO a -> (a -> IO b) -> IO b
(≫=) = IO a -> (a -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(HS.>>=)
instance Monad IO
newtype ID a = ID { forall a. ID a -> a
unID ∷ a }
deriving
( ID a
ID a -> Null (ID a)
forall a. a -> Null a
forall a. Null a => ID a
$cnull :: forall a. Null a => ID a
null :: ID a
Null,ID a -> ID a -> ID a
(ID a -> ID a -> ID a) -> Append (ID a)
forall a. Append a => ID a -> ID a -> ID a
forall a. (a -> a -> a) -> Append a
$c⧺ :: forall a. Append a => ID a -> ID a -> ID a
⧺ :: ID a -> ID a -> ID a
Append,Append (ID a)
Null (ID a)
(Null (ID a), Append (ID a)) => Monoid (ID a)
forall a. (Null a, Append a) => Monoid a
forall a. (Null a, Append a) => Append (ID a)
forall a. (Null a, Append a) => Null (ID a)
Monoid
, ID a
ID a -> Bot (ID a)
forall a. a -> Bot a
forall a. Bot a => ID a
$cbot :: forall a. Bot a => ID a
bot :: ID a
Bot,ID a -> ID a -> ID a
(ID a -> ID a -> ID a) -> Join (ID a)
forall a. Join a => ID a -> ID a -> ID a
forall a. (a -> a -> a) -> Join a
$c⊔ :: forall a. Join a => ID a -> ID a -> ID a
⊔ :: ID a -> ID a -> ID a
Join,Join (ID a)
Bot (ID a)
(Bot (ID a), Join (ID a)) => JoinLattice (ID a)
forall a. (Bot a, Join a) => JoinLattice a
forall a. (Bot a, Join a) => Join (ID a)
forall a. (Bot a, Join a) => Bot (ID a)
JoinLattice
, ID a
ID a -> Top (ID a)
forall a. a -> Top a
forall a. Top a => ID a
$ctop :: forall a. Top a => ID a
top :: ID a
Top,ID a -> ID a -> ID a
(ID a -> ID a -> ID a) -> Meet (ID a)
forall a. Meet a => ID a -> ID a -> ID a
forall a. (a -> a -> a) -> Meet a
$c⊓ :: forall a. Meet a => ID a -> ID a -> ID a
⊓ :: ID a -> ID a -> ID a
Meet,Meet (ID a)
Top (ID a)
(Top (ID a), Meet (ID a)) => MeetLattice (ID a)
forall a. (Top a, Meet a) => MeetLattice a
forall a. (Top a, Meet a) => Meet (ID a)
forall a. (Top a, Meet a) => Top (ID a)
MeetLattice
, MeetLattice (ID a)
JoinLattice (ID a)
(JoinLattice (ID a), MeetLattice (ID a)) => Lattice (ID a)
forall a. (JoinLattice a, MeetLattice a) => Lattice a
forall a. (Bot a, Join a, Top a, Meet a) => MeetLattice (ID a)
forall a. (Bot a, Join a, Top a, Meet a) => JoinLattice (ID a)
Lattice,ID a -> ID a
(ID a -> ID a) -> Dual (ID a)
forall a. Dual a => ID a -> ID a
forall a. (a -> a) -> Dual a
$cdual :: forall a. Dual a => ID a -> ID a
dual :: ID a -> ID a
Dual,ID a -> ID a -> ID a
(ID a -> ID a -> ID a) -> Difference (ID a)
forall a. Difference a => ID a -> ID a -> ID a
forall a. (a -> a -> a) -> Difference a
$c⊟ :: forall a. Difference a => ID a -> ID a -> ID a
⊟ :: ID a -> ID a -> ID a
Difference
)
instance Functor ID where
map :: forall a b. (a -> b) -> ID a -> ID b
map = (a -> b) -> ID a -> ID b
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
mmap
instance Return ID where
return ∷ ∀ a. a → ID a
return :: forall a. a -> ID a
return = a -> ID a
forall a. a -> ID a
ID
instance Bind ID where
(≫=) ∷ ∀ a b. ID a → (a → ID b) → ID b
ID a
x ≫= :: forall a b. ID a -> (a -> ID b) -> ID b
≫= a -> ID b
f = a -> ID b
f (a -> ID b) -> a -> ID b
forall a b. (a -> b) -> a -> b
$ ID a -> a
forall a. ID a -> a
unID ID a
x
instance Monad ID
instance Extract ID where
extract ∷ ∀ a. ID a → a
extract :: forall a. ID a -> a
extract = ID a -> a
forall a. ID a -> a
unID
instance Cobind ID where
(=≫) ∷ ∀ a b. ID a → (ID a → b) → ID b
ID a
xM =≫ :: forall a b. ID a -> (ID a -> b) -> ID b
=≫ ID a -> b
f = b -> ID b
forall a. a -> ID a
ID (b -> ID b) -> b -> ID b
forall a b. (a -> b) -> a -> b
$ ID a -> b
f ID a
xM
instance Comonad ID
newtype ReaderT r m a = ReaderT { forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ∷ r → m a }
runReaderT ∷ ∀ r m a. r → ReaderT r m a → m a
runReaderT :: forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT r
r ReaderT r m a
xM = ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM r
r
instance (Functor m) ⇒ Functor (ReaderT r m) where
map ∷ ∀ a b. (a → b) → ReaderT r m a → ReaderT r m b
map :: forall a b. (a -> b) -> ReaderT r m a -> ReaderT r m b
map a -> b
f = (r -> m b) -> ReaderT r m b
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m b) -> ReaderT r m b)
-> ((r -> m a) -> r -> m b) -> (r -> m a) -> ReaderT r m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (m a -> m b) -> (r -> m a) -> r -> m b
forall a b. (a -> b) -> (r -> a) -> r -> b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> m a -> m b
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f) ((r -> m a) -> ReaderT r m b)
-> (ReaderT r m a -> r -> m a) -> ReaderT r m a -> ReaderT r m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT
instance (Return m) ⇒ Return (ReaderT r m) where
return ∷ ∀ a. a → ReaderT r m a
return :: forall a. a -> ReaderT r m a
return a
x = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return a
x
instance (Bind m) ⇒ Bind (ReaderT r m) where
(≫=) ∷ ∀ a b. ReaderT r m a → (a → ReaderT r m b) → ReaderT r m b
ReaderT r m a
xM ≫= :: forall a b. ReaderT r m a -> (a -> ReaderT r m b) -> ReaderT r m b
≫= a -> ReaderT r m b
k = (r -> m b) -> ReaderT r m b
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m b) -> ReaderT r m b) -> (r -> m b) -> ReaderT r m b
forall a b. (a -> b) -> a -> b
$ \ r
r → do
a
x ← ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM r
r
ReaderT r m b -> r -> m b
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT (a -> ReaderT r m b
k a
x) r
r
instance (Monad m) ⇒ Monad (ReaderT r m)
instance Functor2 (ReaderT r) where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. ReaderT r m₁ a → ReaderT r m₂ a)
map2 :: forall {k} (m₁ :: k -> *) (m₂ :: k -> *).
(forall (a :: k). m₁ a -> m₂ a)
-> forall (a :: k). ReaderT r m₁ a -> ReaderT r m₂ a
map2 forall (a :: k). m₁ a -> m₂ a
f = (r -> m₂ a) -> ReaderT r m₂ a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m₂ a) -> ReaderT r m₂ a)
-> ((r -> m₁ a) -> r -> m₂ a) -> (r -> m₁ a) -> ReaderT r m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (m₁ a -> m₂ a) -> (r -> m₁ a) -> r -> m₂ a
forall a b. (a -> b) -> (r -> a) -> r -> b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map m₁ a -> m₂ a
forall (a :: k). m₁ a -> m₂ a
f ((r -> m₁ a) -> ReaderT r m₂ a)
-> (ReaderT r m₁ a -> r -> m₁ a)
-> ReaderT r m₁ a
-> ReaderT r m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ReaderT r m₁ a -> r -> m₁ a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT
instance (Monad m) ⇒ MonadReader r (ReaderT r m) where
askL ∷ ∀ r'. r ⟢ r' → ReaderT r m r'
askL :: forall r'. (r ⟢ r') -> ReaderT r m r'
askL r ⟢ r'
ℓ = (r -> m r') -> ReaderT r m r'
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m r') -> ReaderT r m r') -> (r -> m r') -> ReaderT r m r'
forall a b. (a -> b) -> a -> b
$ \ r
r → r' -> m r'
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (r' -> m r') -> r' -> m r'
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r -> r'
forall a b. (a ⟢ b) -> a -> b
access r ⟢ r'
ℓ r
r
localL ∷ ∀ r' a. r ⟢ r' → r' → ReaderT r m a → ReaderT r m a
localL :: forall r' a. (r ⟢ r') -> r' -> ReaderT r m a -> ReaderT r m a
localL r ⟢ r'
ℓ r'
r' ReaderT r m a
xM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM (r -> m a) -> r -> m a
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r' -> r -> r
forall (t :: * -> * -> *) a b. Alter t => t a b -> b -> a -> a
update r ⟢ r'
ℓ r'
r' r
r
instance (Func Null m,Null a) ⇒ Null (ReaderT r m a) where
null ∷ ReaderT r m a
null :: ReaderT r m a
null = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → m a
forall a. Null a => a
null
instance (Func Append m,Append a) ⇒ Append (ReaderT r m a) where
(⧺) ∷ ReaderT r m a → ReaderT r m a → ReaderT r m a
⧺ :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a
(⧺) ReaderT r m a
xM₁ ReaderT r m a
xM₂ = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₁ r
r m a -> m a -> m a
forall a. Append a => a -> a -> a
⧺ ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₂ r
r
instance
( Func Null m
, Func Append m
, Monoid a
) ⇒ Monoid (ReaderT r m a)
instance Transformer (ReaderT r) where
lift ∷ ∀ m a. (Monad m) ⇒ m a → ReaderT r m a
lift :: forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
lift m a
xM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → m a
xM
newtype WriterT o m a = WriterT { forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT ∷ m (o ∧ a) }
evalWriterT ∷ ∀ o m a. (Functor m) ⇒ WriterT o m a → m a
evalWriterT :: forall o (m :: * -> *) a. Functor m => WriterT o m a -> m a
evalWriterT = ((o ∧ a) -> a) -> m (o ∧ a) -> m a
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (o ∧ a) -> a
forall a b. (a ∧ b) -> b
snd (m (o ∧ a) -> m a)
-> (WriterT o m a -> m (o ∧ a)) -> WriterT o m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT
instance (Functor m) ⇒ Functor (WriterT o m) where
map ∷ ∀ a b. (a → b) → WriterT o m a → WriterT o m b
map :: forall a b. (a -> b) -> WriterT o m a -> WriterT o m b
map a -> b
f = m (o ∧ b) -> WriterT o m b
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ b) -> WriterT o m b)
-> (m (o ∧ a) -> m (o ∧ b)) -> m (o ∧ a) -> WriterT o m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ((o ∧ a) -> o ∧ b) -> m (o ∧ a) -> m (o ∧ b)
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> (o ∧ a) -> o ∧ b
forall a b. (a -> b) -> (o ∧ a) -> o ∧ b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f) (m (o ∧ a) -> WriterT o m b)
-> (WriterT o m a -> m (o ∧ a)) -> WriterT o m a -> WriterT o m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT
instance (Return m,Null o) ⇒ Return (WriterT o m) where
return ∷ ∀ a. a → WriterT o m a
return :: forall a. a -> WriterT o m a
return a
x = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ (o ∧ a) -> m (o ∧ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
forall a. Null a => a
null o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Monad m,Append o) ⇒ Bind (WriterT o m) where
(≫=) ∷ ∀ a b. WriterT o m a → (a → WriterT o m b) → WriterT o m b
WriterT o m a
xM ≫= :: forall a b. WriterT o m a -> (a -> WriterT o m b) -> WriterT o m b
≫= a -> WriterT o m b
k = m (o ∧ b) -> WriterT o m b
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ b) -> WriterT o m b) -> m (o ∧ b) -> WriterT o m b
forall a b. (a -> b) -> a -> b
$ do
(o
o₁ :* a
x) ← WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM
(o
o₂ :* b
y) ← WriterT o m b -> m (o ∧ b)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (WriterT o m b -> m (o ∧ b)) -> WriterT o m b -> m (o ∧ b)
forall a b. (a -> b) -> a -> b
$ a -> WriterT o m b
k a
x
(o ∧ b) -> m (o ∧ b)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((o
o₁ o -> o -> o
forall a. Append a => a -> a -> a
⧺ o
o₂) o -> b -> o ∧ b
forall a b. a -> b -> a ∧ b
:* b
y)
instance (Monad m,Monoid o) ⇒ Monad (WriterT o m)
instance (Monoid o) ⇒ Functor2 (WriterT o) where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. WriterT o m₁ a → WriterT o m₂ a)
map2 :: forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> WriterT o t →⁻ WriterT o u
map2 forall a. m₁ a -> m₂ a
f = m₂ (o ∧ a) -> WriterT o m₂ a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m₂ (o ∧ a) -> WriterT o m₂ a)
-> (m₁ (o ∧ a) -> m₂ (o ∧ a)) -> m₁ (o ∧ a) -> WriterT o m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ m₁ (o ∧ a) -> m₂ (o ∧ a)
forall a. m₁ a -> m₂ a
f (m₁ (o ∧ a) -> WriterT o m₂ a)
-> (WriterT o m₁ a -> m₁ (o ∧ a))
-> WriterT o m₁ a
-> WriterT o m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ WriterT o m₁ a -> m₁ (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT
instance (Monad m,Null o) ⇒ MonadWriter o (WriterT o m) where
tell ∷ o → WriterT o m ()
tell :: o -> WriterT o m ()
tell o
o = m (o ∧ ()) -> WriterT o m ()
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ ()) -> WriterT o m ()) -> m (o ∧ ()) -> WriterT o m ()
forall a b. (a -> b) -> a -> b
$ (o ∧ ()) -> m (o ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
o o -> () -> o ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
hijack ∷ ∀ a. WriterT o m a → WriterT o m (o ∧ a)
hijack :: forall a. WriterT o m a -> WriterT o m (o ∧ a)
hijack WriterT o m a
xM = m (o ∧ (o ∧ a)) -> WriterT o m (o ∧ a)
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ (o ∧ a)) -> WriterT o m (o ∧ a))
-> m (o ∧ (o ∧ a)) -> WriterT o m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ do
o ∧ a
oa ← WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM
(o ∧ (o ∧ a)) -> m (o ∧ (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((o ∧ (o ∧ a)) -> m (o ∧ (o ∧ a)))
-> (o ∧ (o ∧ a)) -> m (o ∧ (o ∧ a))
forall a b. (a -> b) -> a -> b
$ o
forall a. Null a => a
null o -> (o ∧ a) -> o ∧ (o ∧ a)
forall a b. a -> b -> a ∧ b
:* o ∧ a
oa
instance (Func Null m,Null o,Null a) ⇒ Null (WriterT o m a) where
null ∷ WriterT o m a
null :: WriterT o m a
null = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT m (o ∧ a)
forall a. Null a => a
null
instance (Func Append m,Append o,Append a) ⇒ Append (WriterT o m a) where
(⧺) ∷ WriterT o m a → WriterT o m a → WriterT o m a
WriterT o m a
xM₁ ⧺ :: WriterT o m a -> WriterT o m a -> WriterT o m a
⧺ WriterT o m a
xM₂ = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₁ m (o ∧ a) -> m (o ∧ a) -> m (o ∧ a)
forall a. Append a => a -> a -> a
⧺ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₂
instance
( Func Null m
, Func Append m
, Monoid o
, Monoid a
)
⇒ Monoid (WriterT o m a)
instance (Null o) ⇒ Transformer (WriterT o) where
lift ∷ ∀ m a. (Monad m) ⇒ m a → WriterT o m a
lift :: forall (m :: * -> *) a. Monad m => m a -> WriterT o m a
lift m a
xM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ (o
forall a. Null a => a
null o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:*) (a -> o ∧ a) -> m a -> m (o ∧ a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ m a
xM
newtype StateT s m a = StateT { forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT ∷ s → m (s ∧ a) }
runStateT ∷ ∀ s m a. s → StateT s m a → m (s ∧ a)
runStateT :: forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s StateT s m a
xM = StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM s
s
evalStateT ∷ ∀ s m a. (Functor m) ⇒ s → StateT s m a → m a
evalStateT :: forall s (m :: * -> *) a. Functor m => s -> StateT s m a -> m a
evalStateT s
s = ((s ∧ a) -> a) -> m (s ∧ a) -> m a
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (s ∧ a) -> a
forall a b. (a ∧ b) -> b
snd (m (s ∧ a) -> m a)
-> (StateT s m a -> m (s ∧ a)) -> StateT s m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ s -> StateT s m a -> m (s ∧ a)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s
instance (Functor m) ⇒ Functor (StateT s m) where
map ∷ ∀ a b. (a → b) → StateT s m a → StateT s m b
map :: forall a b. (a -> b) -> StateT s m a -> StateT s m b
map a -> b
f = (s -> m (s ∧ b)) -> StateT s m b
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ b)) -> StateT s m b)
-> ((s -> m (s ∧ a)) -> s -> m (s ∧ b))
-> (s -> m (s ∧ a))
-> StateT s m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (m (s ∧ a) -> m (s ∧ b)) -> (s -> m (s ∧ a)) -> s -> m (s ∧ b)
forall a b. (a -> b) -> (s -> a) -> s -> b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (((s ∧ a) -> s ∧ b) -> m (s ∧ a) -> m (s ∧ b)
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> (s ∧ a) -> s ∧ b
forall a b. (a -> b) -> (s ∧ a) -> s ∧ b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f)) ((s -> m (s ∧ a)) -> StateT s m b)
-> (StateT s m a -> s -> m (s ∧ a)) -> StateT s m a -> StateT s m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT
instance (Return m) ⇒ Return (StateT s m) where
return ∷ ∀ a. a → StateT s m a
return :: forall a. a -> StateT s m a
return a
x = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → (s ∧ a) -> m (s ∧ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> a -> s ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Bind m) ⇒ Bind (StateT s m) where
(≫=) ∷ ∀ a b. StateT s m a → (a → StateT s m b) → StateT s m b
StateT s m a
xM ≫= :: forall a b. StateT s m a -> (a -> StateT s m b) -> StateT s m b
≫= a -> StateT s m b
k = (s -> m (s ∧ b)) -> StateT s m b
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ b)) -> StateT s m b)
-> (s -> m (s ∧ b)) -> StateT s m b
forall a b. (a -> b) -> a -> b
$ \ s
s → do
(s
s' :* a
x) ← StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM s
s
StateT s m b -> s -> m (s ∧ b)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT (a -> StateT s m b
k a
x) s
s'
instance (Monad m) ⇒ Monad (StateT s m)
instance Functor2 (StateT s) where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. StateT s m₁ a → StateT s m₂ a)
map2 :: forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> StateT s t →⁻ StateT s u
map2 forall a. m₁ a -> m₂ a
f = (s -> m₂ (s ∧ a)) -> StateT s m₂ a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m₂ (s ∧ a)) -> StateT s m₂ a)
-> ((s -> m₁ (s ∧ a)) -> s -> m₂ (s ∧ a))
-> (s -> m₁ (s ∧ a))
-> StateT s m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (m₁ (s ∧ a) -> m₂ (s ∧ a)) -> (s -> m₁ (s ∧ a)) -> s -> m₂ (s ∧ a)
forall a b. (a -> b) -> (s -> a) -> s -> b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map m₁ (s ∧ a) -> m₂ (s ∧ a)
forall a. m₁ a -> m₂ a
f ((s -> m₁ (s ∧ a)) -> StateT s m₂ a)
-> (StateT s m₁ a -> s -> m₁ (s ∧ a))
-> StateT s m₁ a
-> StateT s m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ StateT s m₁ a -> s -> m₁ (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT
instance (Return m) ⇒ MonadState s (StateT s m) where
get ∷ StateT s m s
get :: StateT s m s
get = (s -> m (s ∧ s)) -> StateT s m s
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ s)) -> StateT s m s)
-> (s -> m (s ∧ s)) -> StateT s m s
forall a b. (a -> b) -> a -> b
$ \ s
s → (s ∧ s) -> m (s ∧ s)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> s -> s ∧ s
forall a b. a -> b -> a ∧ b
:* s
s)
put ∷ s → StateT s m ()
put :: s -> StateT s m ()
put s
s = (s -> m (s ∧ ())) -> StateT s m ()
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ ())) -> StateT s m ())
-> (s -> m (s ∧ ())) -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ \ s
_ → (s ∧ ()) -> m (s ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> () -> s ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
instance (Func Null m,Null s,Null a) ⇒ Null (StateT s m a) where
null ∷ StateT s m a
null :: StateT s m a
null = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
_ → m (s ∧ a)
forall a. Null a => a
null
instance (Func Append m,Append s,Append a) ⇒ Append (StateT s m a) where
(⧺) ∷ StateT s m a → StateT s m a → StateT s m a
StateT s m a
xM₁ ⧺ :: StateT s m a -> StateT s m a -> StateT s m a
⧺ StateT s m a
xM₂ = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₁ s
s m (s ∧ a) -> m (s ∧ a) -> m (s ∧ a)
forall a. Append a => a -> a -> a
⧺ StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₂ s
s
instance
( Func Null m
, Func Append m
, Monoid s,Monoid a
)
⇒ Monoid (StateT s m a)
type State s = StateT s ID
mkState ∷ (s → s ∧ a) → State s a
mkState :: forall s a. (s -> s ∧ a) -> State s a
mkState s -> s ∧ a
f = (s -> ID (s ∧ a)) -> StateT s ID a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> ID (s ∧ a)) -> StateT s ID a)
-> (s -> ID (s ∧ a)) -> StateT s ID a
forall a b. (a -> b) -> a -> b
$ (s ∧ a) -> ID (s ∧ a)
forall a. a -> ID a
ID ((s ∧ a) -> ID (s ∧ a)) -> (s -> s ∧ a) -> s -> ID (s ∧ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ s -> s ∧ a
f
runState ∷ s → State s a → (s ∧ a)
runState :: forall s a. s -> State s a -> s ∧ a
runState s
s = ID (s ∧ a) -> s ∧ a
forall a. ID a -> a
unID (ID (s ∧ a) -> s ∧ a)
-> (StateT s ID a -> ID (s ∧ a)) -> StateT s ID a -> s ∧ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ s -> StateT s ID a -> ID (s ∧ a)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s
evalState ∷ s → State s a → a
evalState :: forall s a. s -> State s a -> a
evalState s
s = ID a -> a
forall a. ID a -> a
unID (ID a -> a) -> (StateT s ID a -> ID a) -> StateT s ID a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ s -> StateT s ID a -> ID a
forall s (m :: * -> *) a. Functor m => s -> StateT s m a -> m a
evalStateT s
s
instance Transformer (StateT s) where
lift ∷ ∀ m a. (Monad m) ⇒ m a → StateT s m a
lift :: forall (m :: * -> *) a. Monad m => m a -> StateT s m a
lift m a
xM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → (s
s s -> a -> s ∧ a
forall a b. a -> b -> a ∧ b
:*) (a -> s ∧ a) -> m a -> m (s ∧ a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ m a
xM
newtype FailT m a = FailT { forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT ∷ m (𝑂 a) }
instance (Functor m) ⇒ Functor (FailT m) where
map ∷ ∀ a b. (a → b) → FailT m a → FailT m b
map :: forall a b. (a -> b) -> FailT m a -> FailT m b
map a -> b
f = m (𝑂 b) -> FailT m b
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 b) -> FailT m b)
-> (m (𝑂 a) -> m (𝑂 b)) -> m (𝑂 a) -> FailT m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (𝑂 a -> 𝑂 b) -> m (𝑂 a) -> m (𝑂 b)
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> 𝑂 a -> 𝑂 b
forall a b. (a -> b) -> 𝑂 a -> 𝑂 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f) (m (𝑂 a) -> FailT m b)
-> (FailT m a -> m (𝑂 a)) -> FailT m a -> FailT m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT
instance (Return m) ⇒ Return (FailT m) where
return ∷ ∀ a. a → FailT m a
return :: forall a. a -> FailT m a
return a
x = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ 𝑂 a -> m (𝑂 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 a -> m (𝑂 a)) -> 𝑂 a -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ a -> 𝑂 a
forall a. a -> 𝑂 a
Some a
x
instance (Monad m) ⇒ Bind (FailT m) where
(≫=) ∷ ∀ a b. FailT m a → (a → FailT m b) → FailT m b
FailT m a
xM ≫= :: forall a b. FailT m a -> (a -> FailT m b) -> FailT m b
≫= a -> FailT m b
k = m (𝑂 b) -> FailT m b
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 b) -> FailT m b) -> m (𝑂 b) -> FailT m b
forall a b. (a -> b) -> a -> b
$ do
𝑂 a
xO ← FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM
case 𝑂 a
xO of
𝑂 a
None → 𝑂 b -> m (𝑂 b)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return 𝑂 b
forall a. 𝑂 a
None
Some a
x → FailT m b -> m (𝑂 b)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT m b -> m (𝑂 b)) -> FailT m b -> m (𝑂 b)
forall a b. (a -> b) -> a -> b
$ a -> FailT m b
k a
x
instance (Monad m) ⇒ Monad (FailT m)
instance Functor2 FailT where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. FailT m₁ a → FailT m₂ a)
map2 :: forall (t :: * -> *) (u :: * -> *). (t →⁻ u) -> FailT t →⁻ FailT u
map2 forall a. m₁ a -> m₂ a
f = m₂ (𝑂 a) -> FailT m₂ a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m₂ (𝑂 a) -> FailT m₂ a)
-> (m₁ (𝑂 a) -> m₂ (𝑂 a)) -> m₁ (𝑂 a) -> FailT m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ m₁ (𝑂 a) -> m₂ (𝑂 a)
forall a. m₁ a -> m₂ a
f (m₁ (𝑂 a) -> FailT m₂ a)
-> (FailT m₁ a -> m₁ (𝑂 a)) -> FailT m₁ a -> FailT m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ FailT m₁ a -> m₁ (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT
instance (Monad m) ⇒ MonadFail (FailT m) where
abort ∷ ∀ a. FailT m a
abort :: forall a. FailT m a
abort = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ 𝑂 a -> m (𝑂 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return 𝑂 a
forall a. 𝑂 a
None
(⎅) ∷ ∀ a. FailT m a → FailT m a → FailT m a
FailT m a
xM₁ ⎅ :: forall a. FailT m a -> FailT m a -> FailT m a
⎅ FailT m a
xM₂ = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ do
𝑂 a
xO₁ ← FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₁
case 𝑂 a
xO₁ of
𝑂 a
None → FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₂
Some a
x → 𝑂 a -> m (𝑂 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 a -> m (𝑂 a)) -> 𝑂 a -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ a -> 𝑂 a
forall a. a -> 𝑂 a
Some a
x
instance (Func Null m,Null a) ⇒ Null (FailT m a) where
null ∷ FailT m a
null :: FailT m a
null = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT m (𝑂 a)
forall a. Null a => a
null
instance (Func Append m,Append a) ⇒ Append (FailT m a) where
(⧺) ∷ FailT m a → FailT m a → FailT m a
FailT m a
xM₁ ⧺ :: FailT m a -> FailT m a -> FailT m a
⧺ FailT m a
xM₂ = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₁ m (𝑂 a) -> m (𝑂 a) -> m (𝑂 a)
forall a. Append a => a -> a -> a
⧺ FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₂
instance
( Func Null m
, Func Append m
, Monoid a
)
⇒ Monoid (FailT m a)
instance Transformer FailT where
lift ∷ ∀ m a. (Monad m) ⇒ m a → FailT m a
lift :: forall (m :: * -> *) a. Monad m => m a -> FailT m a
lift m a
xM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ a -> 𝑂 a
forall a. a -> 𝑂 a
Some (a -> 𝑂 a) -> m a -> m (𝑂 a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ m a
xM
newtype ErrorT e m a = ErrorT { forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ∷ m (e ∨ a) }
instance (Functor m) ⇒ Functor (ErrorT e m) where
map ∷ ∀ a b. (a → b) → ErrorT e m a → ErrorT e m b
map :: forall a b. (a -> b) -> ErrorT e m a -> ErrorT e m b
map a -> b
f = m (e ∨ b) -> ErrorT e m b
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ b) -> ErrorT e m b)
-> (m (e ∨ a) -> m (e ∨ b)) -> m (e ∨ a) -> ErrorT e m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ((e ∨ a) -> e ∨ b) -> m (e ∨ a) -> m (e ∨ b)
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> (e ∨ a) -> e ∨ b
forall a b. (a -> b) -> (e ∨ a) -> e ∨ b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f) (m (e ∨ a) -> ErrorT e m b)
-> (ErrorT e m a -> m (e ∨ a)) -> ErrorT e m a -> ErrorT e m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT
instance (Return m) ⇒ Return (ErrorT e m) where
return ∷ ∀ a. a → ErrorT e m a
return :: forall a. a -> ErrorT e m a
return a
x = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ (e ∨ a) -> m (e ∨ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ a) -> m (e ∨ a)) -> (e ∨ a) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ a -> e ∨ a
forall a b. b -> a ∨ b
Inr a
x
instance (Monad m) ⇒ Bind (ErrorT e m) where
(≫=) ∷ ∀ a b. ErrorT e m a → (a → ErrorT e m b) → ErrorT e m b
ErrorT e m a
xM ≫= :: forall a b. ErrorT e m a -> (a -> ErrorT e m b) -> ErrorT e m b
≫= a -> ErrorT e m b
k = m (e ∨ b) -> ErrorT e m b
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ b) -> ErrorT e m b) -> m (e ∨ b) -> ErrorT e m b
forall a b. (a -> b) -> a -> b
$ do
e ∨ a
ex ← ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM
case e ∨ a
ex of
Inl e
e → (e ∨ b) -> m (e ∨ b)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ b) -> m (e ∨ b)) -> (e ∨ b) -> m (e ∨ b)
forall a b. (a -> b) -> a -> b
$ e -> e ∨ b
forall a b. a -> a ∨ b
Inl e
e
Inr a
x → ErrorT e m b -> m (e ∨ b)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m b -> m (e ∨ b)) -> ErrorT e m b -> m (e ∨ b)
forall a b. (a -> b) -> a -> b
$ a -> ErrorT e m b
k a
x
instance (Monad m) ⇒ Monad (ErrorT e m)
instance Functor2 (ErrorT e) where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. ErrorT e m₁ a → ErrorT e m₂ a)
map2 :: forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> ErrorT e t →⁻ ErrorT e u
map2 forall a. m₁ a -> m₂ a
f = m₂ (e ∨ a) -> ErrorT e m₂ a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m₂ (e ∨ a) -> ErrorT e m₂ a)
-> (m₁ (e ∨ a) -> m₂ (e ∨ a)) -> m₁ (e ∨ a) -> ErrorT e m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ m₁ (e ∨ a) -> m₂ (e ∨ a)
forall a. m₁ a -> m₂ a
f (m₁ (e ∨ a) -> ErrorT e m₂ a)
-> (ErrorT e m₁ a -> m₁ (e ∨ a)) -> ErrorT e m₁ a -> ErrorT e m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ErrorT e m₁ a -> m₁ (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT
instance (Monad m) ⇒ MonadError e (ErrorT e m) where
throw ∷ ∀ a. e → ErrorT e m a
throw :: forall a. e -> ErrorT e m a
throw e
e = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ (e ∨ a) -> m (e ∨ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ a) -> m (e ∨ a)) -> (e ∨ a) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ e -> e ∨ a
forall a b. a -> a ∨ b
Inl e
e
catch ∷ ∀ a. ErrorT e m a → (e → ErrorT e m a) → ErrorT e m a
catch :: forall a. ErrorT e m a -> (e -> ErrorT e m a) -> ErrorT e m a
catch ErrorT e m a
xM e -> ErrorT e m a
k = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ do
e ∨ a
ex ← ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM
case e ∨ a
ex of
Inl e
e → ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m a -> m (e ∨ a)) -> ErrorT e m a -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ e -> ErrorT e m a
k e
e
Inr a
x → (e ∨ a) -> m (e ∨ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ a) -> m (e ∨ a)) -> (e ∨ a) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ a -> e ∨ a
forall a b. b -> a ∨ b
Inr a
x
instance (Func Null m,Null a) ⇒ Null (ErrorT e m a) where
null ∷ ErrorT e m a
null :: ErrorT e m a
null = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT m (e ∨ a)
forall a. Null a => a
null
instance (Func Append m,Append e,Append a) ⇒ Append (ErrorT e m a) where
(⧺) ∷ ErrorT e m a → ErrorT e m a → ErrorT e m a
ErrorT e m a
xM₁ ⧺ :: ErrorT e m a -> ErrorT e m a -> ErrorT e m a
⧺ ErrorT e m a
xM₂ = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₁ m (e ∨ a) -> m (e ∨ a) -> m (e ∨ a)
forall a. Append a => a -> a -> a
⧺ ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₂
instance
( Func Null m
, Func Append m
, Append e,Monoid a
)
⇒ Monoid (ErrorT e m a)
instance Transformer (ErrorT e) where
lift ∷ ∀ m a. (Monad m) ⇒ m a → ErrorT e m a
lift :: forall (m :: * -> *) a. Monad m => m a -> ErrorT e m a
lift m a
xM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ a -> e ∨ a
forall a b. b -> a ∨ b
Inr (a -> e ∨ a) -> m a -> m (e ∨ a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ m a
xM
newtype DelayT m a = DelayT { forall {k} (m :: k -> *) (a :: k). DelayT m a -> () -> m a
unDelayT ∷ () → m a }
runDelayT ∷ DelayT m a → m a
runDelayT :: forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT = () -> (() -> m a) -> m a
forall a b. a -> (a -> b) -> b
appto () ((() -> m a) -> m a)
-> (DelayT m a -> () -> m a) -> DelayT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ DelayT m a -> () -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> () -> m a
unDelayT
instance (Functor m) ⇒ Functor (DelayT m) where map :: forall a b. (a -> b) -> DelayT m a -> DelayT m b
map a -> b
f DelayT m a
xM = (() -> m b) -> DelayT m b
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m b) -> DelayT m b) -> (() -> m b) -> DelayT m b
forall a b. (a -> b) -> a -> b
$ \ () → (a -> b) -> m a -> m b
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f (m a -> m b) -> m a -> m b
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM
instance (Return m) ⇒ Return (DelayT m) where return :: forall a. a -> DelayT m a
return = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a)
-> (m a -> () -> m a) -> m a -> DelayT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ m a -> () -> m a
forall a b. a -> b -> a
const (m a -> DelayT m a) -> (a -> m a) -> a -> DelayT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return
instance (Bind m) ⇒ Bind (DelayT m) where DelayT m a
xM ≫= :: forall a b. DelayT m a -> (a -> DelayT m b) -> DelayT m b
≫= a -> DelayT m b
f = (() -> m b) -> DelayT m b
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m b) -> DelayT m b) -> (() -> m b) -> DelayT m b
forall a b. (a -> b) -> a -> b
$ \ () → DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM m a -> (a -> m b) -> m b
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
≫= DelayT m b -> m b
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m b -> m b) -> (a -> DelayT m b) -> a -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ a -> DelayT m b
f
instance (Monad m) ⇒ Monad (DelayT m)
instance Functor2 DelayT where
map2 ∷ ∀ m₁ m₂. (∀ a. m₁ a → m₂ a) → (∀ a. DelayT m₁ a → DelayT m₂ a)
map2 :: forall {k} (m₁ :: k -> *) (m₂ :: k -> *).
(forall (a :: k). m₁ a -> m₂ a)
-> forall (a :: k). DelayT m₁ a -> DelayT m₂ a
map2 forall (a :: k). m₁ a -> m₂ a
f = (() -> m₂ a) -> DelayT m₂ a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m₂ a) -> DelayT m₂ a)
-> ((() -> m₁ a) -> () -> m₂ a) -> (() -> m₁ a) -> DelayT m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (m₁ a -> m₂ a) -> (() -> m₁ a) -> () -> m₂ a
forall a b. (a -> b) -> (() -> a) -> () -> b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map m₁ a -> m₂ a
forall (a :: k). m₁ a -> m₂ a
f ((() -> m₁ a) -> DelayT m₂ a)
-> (DelayT m₁ a -> () -> m₁ a) -> DelayT m₁ a -> DelayT m₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ DelayT m₁ a -> () -> m₁ a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> () -> m a
unDelayT
instance MonadDelay (DelayT m) where
delay :: forall (a :: k). (() -> DelayT m a) -> DelayT m a
delay () -> DelayT m a
xMU = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m a -> m a) -> DelayT m a -> m a
forall a b. (a -> b) -> a -> b
$ () -> DelayT m a
xMU ()
instance (Const Null m) ⇒ Null (DelayT m a) where
null :: DelayT m a
null = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a
forall a. Null a => a
null
instance (Const Append m) ⇒ Append (DelayT m a) where
DelayT m a
xM₁ ⧺ :: DelayT m a -> DelayT m a -> DelayT m a
⧺ DelayT m a
xM₂ = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM₁ m a -> m a -> m a
forall a. Append a => a -> a -> a
⧺ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM₂
instance (Const Null m,Const Append m) ⇒ Monoid (DelayT m a)
instance Transformer DelayT where lift :: forall (m :: * -> *) a. Monad m => m a -> DelayT m a
lift m a
xM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a
xM
newtype NondetT m a = NondetT { forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT ∷ m (𝑄 a) }
instance (Functor m) ⇒ Functor (NondetT m) where
map ∷ ∀ a b. (a → b) → NondetT m a → NondetT m b
map :: forall a b. (a -> b) -> NondetT m a -> NondetT m b
map a -> b
f NondetT m a
xM = m (𝑄 b) -> NondetT m b
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 b) -> NondetT m b) -> m (𝑄 b) -> NondetT m b
forall a b. (a -> b) -> a -> b
$ (𝑄 a -> 𝑄 b) -> m (𝑄 a) -> m (𝑄 b)
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((a -> b) -> 𝑄 a -> 𝑄 b
forall a b. (a -> b) -> 𝑄 a -> 𝑄 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> b
f) (m (𝑄 a) -> m (𝑄 b)) -> m (𝑄 a) -> m (𝑄 b)
forall a b. (a -> b) -> a -> b
$ NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM
instance (Return m) ⇒ Return (NondetT m) where
return ∷ ∀ a. a → NondetT m a
return :: forall a. a -> NondetT m a
return a
x = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> m (𝑄 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 a -> m (𝑄 a)) -> 𝑄 a -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ a -> 𝑄 a
forall a t. Single a t => a -> t
single a
x
instance (Bind m,Func Monoid m) ⇒ Bind (NondetT m) where
(≫=) ∷ ∀ a b. NondetT m a → (a → NondetT m b) → NondetT m b
NondetT m a
xM ≫= :: forall a b. NondetT m a -> (a -> NondetT m b) -> NondetT m b
≫= a -> NondetT m b
k = m (𝑄 b) -> NondetT m b
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 b) -> NondetT m b) -> m (𝑄 b) -> NondetT m b
forall a b. (a -> b) -> a -> b
$ do
𝑄 a
xs ← NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM
NondetT m b -> m (𝑄 b)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT (NondetT m b -> m (𝑄 b)) -> NondetT m b -> m (𝑄 b)
forall a b. (a -> b) -> a -> b
$ NondetT m b
-> (NondetT m b -> NondetT m b -> NondetT m b)
-> 𝐼 (NondetT m b)
-> NondetT m b
forall a t b. ToIter a t => b -> (a -> b -> b) -> t -> b
foldr NondetT m b
forall a. NondetT m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero NondetT m b -> NondetT m b -> NondetT m b
forall a. NondetT m a -> NondetT m a -> NondetT m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞) (𝐼 (NondetT m b) -> NondetT m b) -> 𝐼 (NondetT m b) -> NondetT m b
forall a b. (a -> b) -> a -> b
$ (a -> NondetT m b) -> 𝐼 a -> 𝐼 (NondetT m b)
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> NondetT m b
k (𝐼 a -> 𝐼 (NondetT m b)) -> 𝐼 a -> 𝐼 (NondetT m b)
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter 𝑄 a
xs
instance (Monad m,Func Monoid m) ⇒ Monad (NondetT m)
instance (Func Monoid m) ⇒ MonadNondet (NondetT m) where
mzero ∷ ∀ a. NondetT m a
mzero :: forall a. NondetT m a
mzero = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a)
forall a. Null a => a
null
(⊞) ∷ ∀ a. NondetT m a → NondetT m a → NondetT m a
NondetT m a
xM₁ ⊞ :: forall a. NondetT m a -> NondetT m a -> NondetT m a
⊞ NondetT m a
xM₂ = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₁ m (𝑄 a) -> m (𝑄 a) -> m (𝑄 a)
forall a. Append a => a -> a -> a
⧺ NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₂
instance Transformer NondetT where
lift ∷ ∀ m a. (Monad m) ⇒ m a → NondetT m a
lift :: forall (m :: * -> *) a. Monad m => m a -> NondetT m a
lift m a
xM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ a -> 𝑄 a
forall a t. Single a t => a -> t
single (a -> 𝑄 a) -> m a -> m (𝑄 a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ m a
xM
newtype ContT u m a = ContT { forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ∷ (a → m u) → m u }
runContT ∷ (a → m u) → ContT u m a → m u
runContT :: forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT = (ContT u m a -> (a -> m u) -> m u)
-> (a -> m u) -> ContT u m a -> m u
forall a b c. (a -> b -> c) -> b -> a -> c
flip ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT
evalContT ∷ (Return m) ⇒ ContT u m u → m u
evalContT :: forall (m :: * -> *) u. Return m => ContT u m u -> m u
evalContT = (u -> m u) -> ContT u m u -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT u -> m u
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return
instance Functor (ContT u m) where
map ∷ ∀ a b. (a → b) → ContT u m a → ContT u m b
map :: forall a b. (a -> b) -> ContT u m a -> ContT u m b
map a -> b
f ContT u m a
xM = ((b -> m u) -> m u) -> ContT u m b
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((b -> m u) -> m u) -> ContT u m b)
-> ((b -> m u) -> m u) -> ContT u m b
forall a b. (a -> b) -> a -> b
$ \ (b -> m u
k ∷ b → m r) → ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ a
x → b -> m u
k (b -> m u) -> b -> m u
forall a b. (a -> b) -> a -> b
$ a -> b
f a
x
instance Return (ContT u m) where
return ∷ ∀ a. a → ContT u m a
return :: forall a. a -> ContT u m a
return a
x = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → a -> m u
k a
x
instance Bind (ContT u m) where
(≫=) ∷ ∀ a b. ContT u m a → (a → ContT u m b) → ContT u m b
ContT u m a
xM ≫= :: forall a b. ContT u m a -> (a -> ContT u m b) -> ContT u m b
≫= a -> ContT u m b
kk = ((b -> m u) -> m u) -> ContT u m b
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((b -> m u) -> m u) -> ContT u m b)
-> ((b -> m u) -> m u) -> ContT u m b
forall a b. (a -> b) -> a -> b
$ \ (b -> m u
k ∷ b → m r) → ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) → ContT u m b -> (b -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT (a -> ContT u m b
kk a
x) b -> m u
k
instance Monad (ContT u m)
instance Functor2Iso (ContT u) where
map2iso ∷ ∀ m₁ m₂. Iso2 m₁ m₂ → ∀ a. ContT u m₁ a → ContT u m₂ a
map2iso :: forall (t :: * -> *) (u :: * -> *).
Iso2 t u -> ContT u t →⁻ ContT u u
map2iso Iso2 m₁ m₂
i ContT u m₁ a
xM = ((a -> m₂ u) -> m₂ u) -> ContT u m₂ a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m₂ u) -> m₂ u) -> ContT u m₂ a)
-> ((a -> m₂ u) -> m₂ u) -> ContT u m₂ a
forall a b. (a -> b) -> a -> b
$ \ (a -> m₂ u
k ∷ a → m₂ r) →
Iso2 m₁ m₂ -> m₁ →⁻ m₂
forall (t :: * -> *) (u :: * -> *). Iso2 t u -> t →⁻ u
ito2 Iso2 m₁ m₂
i (m₁ u -> m₂ u) -> m₁ u -> m₂ u
forall a b. (a -> b) -> a -> b
$ ContT u m₁ a -> (a -> m₁ u) -> m₁ u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m₁ a
xM ((a -> m₁ u) -> m₁ u) -> (a -> m₁ u) -> m₁ u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
Iso2 m₁ m₂ -> m₂ →⁻ m₁
forall (t :: * -> *) (u :: * -> *). Iso2 t u -> u →⁻ t
ifr2 Iso2 m₁ m₂
i (m₂ u -> m₁ u) -> m₂ u -> m₁ u
forall a b. (a -> b) -> a -> b
$ a -> m₂ u
k a
x
instance (Monad m) ⇒ MonadCont u (ContT u m) where
callCC ∷ ∀ a. ((a → ContT u m u) → ContT u m u) → ContT u m a
callCC :: forall a. ((a -> ContT u m u) -> ContT u m u) -> ContT u m a
callCC (a -> ContT u m u) -> ContT u m u
kk = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) →
(u -> m u) -> ContT u m u -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT u -> m u
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (ContT u m u -> m u) -> ContT u m u -> m u
forall a b. (a -> b) -> a -> b
$ (a -> ContT u m u) -> ContT u m u
kk ((a -> ContT u m u) -> ContT u m u)
-> (a -> ContT u m u) -> ContT u m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
((u -> m u) -> m u) -> ContT u m u
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((u -> m u) -> m u) -> ContT u m u)
-> ((u -> m u) -> m u) -> ContT u m u
forall a b. (a -> b) -> a -> b
$ \ (u -> m u
k' ∷ r → m r) →
u -> m u
k' (u -> m u) -> m u -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ a -> m u
k a
x
withC ∷ ∀ a. (a → ContT u m u) → ContT u m a → ContT u m u
withC :: forall a. (a -> ContT u m u) -> ContT u m a -> ContT u m u
withC a -> ContT u m u
k₁ ContT u m a
xM = ((u -> m u) -> m u) -> ContT u m u
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((u -> m u) -> m u) -> ContT u m u)
-> ((u -> m u) -> m u) -> ContT u m u
forall a b. (a -> b) -> a -> b
$ \ (u -> m u
k₂ ∷ u → m u) →
u -> m u
k₂ (u -> m u) -> m u -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
(u -> m u) -> ContT u m u -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT u -> m u
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (ContT u m u -> m u) -> ContT u m u -> m u
forall a b. (a -> b) -> a -> b
$ a -> ContT u m u
k₁ a
x
instance (Func Null m,Null u) ⇒ Null (ContT u m a) where
null ∷ ContT u m a
null :: ContT u m a
null = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
_ ∷ a → m r) → m u
forall a. Null a => a
null
instance (Func Append m,Append u) ⇒ Append (ContT u m a) where
(⧺) ∷ ContT u m a → ContT u m a → ContT u m a
ContT u m a
xM₁ ⧺ :: ContT u m a -> ContT u m a -> ContT u m a
⧺ ContT u m a
xM₂ = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM₁ a -> m u
k m u -> m u -> m u
forall a. Append a => a -> a -> a
⧺ ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM₂ a -> m u
k
instance
( Func Null m
, Func Append m
, Monoid u
)
⇒ Monoid (ContT u m a)
instance Transformer (ContT u) where
lift ∷ ∀ m a. (Monad m) ⇒ m a → ContT u m a
lift :: forall (m :: * -> *) a. Monad m => m a -> ContT u m a
lift m a
xM = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
κ ∷ a → m r) → a -> m u
κ (a -> m u) -> m a -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ m a
xM
newtype UContT m a = UContT { forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT ∷ ∀ u. (a → m u) → m u }
runUContT ∷ ∀ u m a. (a → m u) → UContT m a → m u
runUContT :: forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM = UContT m a -> forall (u :: k). (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM a -> m u
k
evalUContT ∷ (Return m) ⇒ UContT m a → m a
evalUContT :: forall (m :: * -> *) a. Return m => UContT m a -> m a
evalUContT = (a -> m a) -> UContT m a -> m a
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return
instance Functor (UContT m) where
map ∷ ∀ a b. (a → b) → UContT m a → UContT m b
map :: forall a b. (a -> b) -> UContT m a -> UContT m b
map a -> b
f UContT m a
xM = (forall (u :: k). (b -> m u) -> m u) -> UContT m b
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall (u :: k). (b -> m u) -> m u) -> UContT m b)
-> (forall (u :: k). (b -> m u) -> m u) -> UContT m b
forall a b. (a -> b) -> a -> b
HS.$ \ (b -> m u
k ∷ b → m u) → UContT m a -> forall (u :: k). (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ a
x → b -> m u
k (b -> m u) -> b -> m u
forall a b. (a -> b) -> a -> b
$ a -> b
f a
x
instance Return (UContT m) where
return ∷ ∀ a. a → UContT m a
return :: forall a. a -> UContT m a
return a
x = (forall (u :: k). (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall (u :: k). (a -> m u) -> m u) -> UContT m a)
-> (forall (u :: k). (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
k ∷ a → m u) → a -> m u
k a
x
instance Bind (UContT m) where
(≫=) ∷ ∀ a b. UContT m a → (a → UContT m b) → UContT m b
UContT m a
xM ≫= :: forall a b. UContT m a -> (a -> UContT m b) -> UContT m b
≫= a -> UContT m b
kk = (forall (u :: k). (b -> m u) -> m u) -> UContT m b
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall (u :: k). (b -> m u) -> m u) -> UContT m b)
-> (forall (u :: k). (b -> m u) -> m u) -> UContT m b
forall a b. (a -> b) -> a -> b
HS.$ \ (b -> m u
k ∷ b → m u) → UContT m a -> forall (u :: k). (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) → UContT m b -> forall (u :: k). (b -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT (a -> UContT m b
kk a
x) b -> m u
k
instance Monad (UContT m)
instance Functor2Iso UContT where
map2iso ∷ ∀ m₁ m₂. Iso2 m₁ m₂ → ∀ a. UContT m₁ a → UContT m₂ a
map2iso :: forall (t :: * -> *) (u :: * -> *).
Iso2 t u -> UContT t →⁻ UContT u
map2iso Iso2 m₁ m₂
i UContT m₁ a
xM = (forall u. (a -> m₂ u) -> m₂ u) -> UContT m₂ a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m₂ u) -> m₂ u) -> UContT m₂ a)
-> (forall u. (a -> m₂ u) -> m₂ u) -> UContT m₂ a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m₂ u
k ∷ a → m₂ u) →
Iso2 m₁ m₂ -> m₁ →⁻ m₂
forall (t :: * -> *) (u :: * -> *). Iso2 t u -> t →⁻ u
ito2 Iso2 m₁ m₂
i (m₁ u -> m₂ u) -> m₁ u -> m₂ u
forall a b. (a -> b) -> a -> b
$ UContT m₁ a -> forall u. (a -> m₁ u) -> m₁ u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m₁ a
xM ((a -> m₁ u) -> m₁ u) -> (a -> m₁ u) -> m₁ u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
Iso2 m₁ m₂ -> m₂ →⁻ m₁
forall (t :: * -> *) (u :: * -> *). Iso2 t u -> u →⁻ t
ifr2 Iso2 m₁ m₂
i (m₂ u -> m₁ u) -> m₂ u -> m₁ u
forall a b. (a -> b) -> a -> b
$ a -> m₂ u
k a
x
instance (Monad m) ⇒ MonadUCont (UContT m) where
ucallCC ∷ ∀ a. (∀ u. (a → UContT m u) → UContT m u) → UContT m a
ucallCC :: forall a. (forall u. (a -> UContT m u) -> UContT m u) -> UContT m a
ucallCC forall u. (a -> UContT m u) -> UContT m u
ff = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
𝓀 ∷ a → m u₁) →
UContT m u -> m u
forall (m :: * -> *) a. Return m => UContT m a -> m a
evalUContT (UContT m u -> m u) -> UContT m u -> m u
forall a b. (a -> b) -> a -> b
$ (a -> UContT m u) -> UContT m u
forall u. (a -> UContT m u) -> UContT m u
ff ((a -> UContT m u) -> UContT m u)
-> (a -> UContT m u) -> UContT m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
(forall u. (u -> m u) -> m u) -> UContT m u
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (u -> m u) -> m u) -> UContT m u)
-> (forall u. (u -> m u) -> m u) -> UContT m u
forall a b. (a -> b) -> a -> b
HS.$ \ (u -> m u
𝓀' ∷ u₁ → m u₂) →
u -> m u
𝓀' (u -> m u) -> m u -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ a -> m u
𝓀 a
x
uwithC ∷ ∀ a u. (a → UContT m u) → UContT m a → UContT m u
uwithC :: forall a u. (a -> UContT m u) -> UContT m a -> UContT m u
uwithC a -> UContT m u
f UContT m a
xM = (forall u. (u -> m u) -> m u) -> UContT m u
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (u -> m u) -> m u) -> UContT m u)
-> (forall u. (u -> m u) -> m u) -> UContT m u
forall a b. (a -> b) -> a -> b
HS.$ \ (u -> m u
𝓀 ∷ u → m u₁) →
u -> m u
𝓀 (u -> m u) -> m u -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ UContT m a -> forall u. (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
UContT m u -> m u
forall (m :: * -> *) a. Return m => UContT m a -> m a
evalUContT (UContT m u -> m u) -> UContT m u -> m u
forall a b. (a -> b) -> a -> b
$ a -> UContT m u
f a
x
instance (Const Null m) ⇒ Null (UContT m a) where
null ∷ UContT m a
null :: UContT m a
null = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
_ ∷ a → m u) → m u
forall a. Null a => a
null
instance (Const Append m) ⇒ Append (UContT m a) where
(⧺) ∷ UContT m a → UContT m a → UContT m a
UContT m a
xM₁ ⧺ :: UContT m a -> UContT m a -> UContT m a
⧺ UContT m a
xM₂ = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
𝓀 ∷ a → m u) → UContT m a -> forall u. (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM₁ a -> m u
𝓀 m u -> m u -> m u
forall a. Append a => a -> a -> a
⧺ UContT m a -> forall u. (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM₂ a -> m u
𝓀
instance
( Const Monoid m
) ⇒ Monoid (UContT m a)
instance Transformer UContT where
lift ∷ ∀ m a. (Monad m) ⇒ m a → UContT m a
lift :: forall (m :: * -> *) a. Monad m => m a -> UContT m a
lift m a
xM = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
𝓀 ∷ a → m u) → a -> m u
𝓀 (a -> m u) -> m a -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ m a
xM
instance LiftIO (ReaderT r) where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → ReaderT r m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ReaderT r m a
liftIO forall a. IO a -> m a
ioM IO a
xM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
instance (Monad m,MonadIO m) ⇒ MonadIO (ReaderT r m) where
io :: forall a. IO a -> ReaderT r m a
io = (forall a. IO a -> m a) -> forall a. IO a -> ReaderT r m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader (ReaderT r) where
liftAskL ∷ ∀ m r'. (Monad m) ⇒ (∀ r''. r' ⟢ r'' → m r'') → (∀ r''. r' ⟢ r'' → ReaderT r m r'')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> ReaderT r m r'
liftAskL forall r''. (r' ⟢ r'') -> m r''
askLM r' ⟢ r''
ℓ = (r -> m r'') -> ReaderT r m r''
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m r'') -> ReaderT r m r'')
-> (r -> m r'') -> ReaderT r m r''
forall a b. (a -> b) -> a -> b
$ \ r
_ → (r' ⟢ r'') -> m r''
forall r''. (r' ⟢ r'') -> m r''
askLM r' ⟢ r''
ℓ
liftLocalL ∷ ∀ m r'. (Monad m) ⇒ (∀ r'' a. r' ⟢ r'' → r'' → m a → m a) → (∀ r'' a. r' ⟢ r'' → r'' → ReaderT r m a → ReaderT r m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> ReaderT r m a -> ReaderT r m a
liftLocalL forall r'' a. (r' ⟢ r'') -> r'' -> m a -> m a
localLM r' ⟢ r''
ℓ r''
r' ReaderT r m a
xM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → (r' ⟢ r'') -> r'' -> m a -> m a
forall r'' a. (r' ⟢ r'') -> r'' -> m a -> m a
localLM r' ⟢ r''
ℓ r''
r' (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM r
r
instance LiftWriter (ReaderT r) where
liftTell ∷ ∀ m o. (Monad m) ⇒ (o → m ()) → (o → ReaderT r m ())
liftTell :: forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> ReaderT r m ()
liftTell o -> m ()
tellM o
o = (r -> m ()) -> ReaderT r m ()
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m ()) -> ReaderT r m ()) -> (r -> m ()) -> ReaderT r m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ → o -> m ()
tellM o
o
liftHijack ∷ ∀ m o. (Monad m) ⇒ (∀ a. m a → m (o ∧ a)) → (∀ a. ReaderT r m a → ReaderT r m (o ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. ReaderT r m a -> ReaderT r m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM ReaderT r m a
xM = (r -> m (o ∧ a)) -> ReaderT r m (o ∧ a)
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m (o ∧ a)) -> ReaderT r m (o ∧ a))
-> (r -> m (o ∧ a)) -> ReaderT r m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ r
r → m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
hijackM (m a -> m (o ∧ a)) -> m a -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM r
r
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (ReaderT r m) where
tell :: o -> ReaderT r m ()
tell = (o -> m ()) -> o -> ReaderT r m ()
forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> ReaderT r m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. ReaderT r m a -> ReaderT r m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. ReaderT r m a -> ReaderT r m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. ReaderT r m a -> ReaderT r m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState (ReaderT r) where
liftGet ∷ ∀ m s. (Monad m) ⇒ m s → ReaderT r m s
liftGet :: forall (m :: * -> *) s. Monad m => m s -> ReaderT r m s
liftGet m s
getM = (r -> m s) -> ReaderT r m s
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m s) -> ReaderT r m s) -> (r -> m s) -> ReaderT r m s
forall a b. (a -> b) -> a -> b
$ \ r
_ → m s
getM
liftPut ∷ ∀ m s. (Monad m) ⇒ (s → m ()) → (s → ReaderT r m ())
liftPut :: forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> ReaderT r m ()
liftPut s -> m ()
putM s
s = (r -> m ()) -> ReaderT r m ()
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m ()) -> ReaderT r m ()) -> (r -> m ()) -> ReaderT r m ()
forall a b. (a -> b) -> a -> b
$ \ r
_ → s -> m ()
putM s
s
instance (Monad m,MonadState s m) ⇒ MonadState s (ReaderT r m) where
get :: ReaderT r m s
get = m s -> ReaderT r m s
forall (m :: * -> *) s. Monad m => m s -> ReaderT r m s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> ReaderT r m ()
put = (s -> m ()) -> s -> ReaderT r m ()
forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> ReaderT r m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail (ReaderT r) where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ReaderT r m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftAbort forall a. m a
abortM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → m a
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. ReaderT r m a → ReaderT r m a → ReaderT r m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
liftTry forall a. m a -> m a -> m a
tryM ReaderT r m a
xM₁ ReaderT r m a
xM₂ = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → m a -> m a -> m a
forall a. m a -> m a -> m a
tryM (ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₁ r
r) (ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₂ r
r)
instance (Monad m,MonadFail m) ⇒ MonadFail (ReaderT r m) where
abort :: forall a. ReaderT r m a
abort = (forall a. m a) -> forall a. ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError (ReaderT r) where
liftThrow ∷ ∀ m e. (Monad m) ⇒ (∀ a. e → m a) → (∀ a. e → ReaderT r m a)
liftThrow :: forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> ReaderT r m a
liftThrow forall a. e -> m a
throwM e
e = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → e -> m a
forall a. e -> m a
throwM e
e
liftCatch ∷ ∀ m e. (Monad m) ⇒ (∀ a. m a → (e → m a) → m a) → (∀ a. ReaderT r m a → (e → ReaderT r m a) → ReaderT r m a)
liftCatch :: forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM ReaderT r m a
xM e -> ReaderT r m a
k = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
catchM (ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM r
r) (\ e
e → ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT (e -> ReaderT r m a
k e
e) r
r)
instance (Monad m,MonadError e m) ⇒ MonadError e (ReaderT r m) where
throw :: forall a. e -> ReaderT r m a
throw = (forall a. e -> m a) -> forall a. e -> ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> ReaderT r m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay (ReaderT r) where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ReaderT r m a) -> ReaderT r m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> ReaderT r m a
xMU = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → (() -> m a) -> m a
forall a. (() -> m a) -> m a
delayM ((() -> m a) -> m a) -> (() -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ \ () → r -> ReaderT r m a -> m a
forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT r
r (ReaderT r m a -> m a) -> ReaderT r m a -> m a
forall a b. (a -> b) -> a -> b
$ () -> ReaderT r m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (ReaderT r m) where
delay :: forall a. (() -> ReaderT r m a) -> ReaderT r m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> ReaderT r m a) -> ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ReaderT r m a) -> ReaderT r m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet (ReaderT r) where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ReaderT r m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftMzero forall a. m a
mzeroM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → m a
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. ReaderT r m a → ReaderT r m a → ReaderT r m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
liftMplus forall a. m a -> m a -> m a
mplusM ReaderT r m a
xM₁ ReaderT r m a
xM₂ = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r → m a -> m a -> m a
forall a. m a -> m a -> m a
mplusM (ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₁ r
r) (ReaderT r m a -> r -> m a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT ReaderT r m a
xM₂ r
r)
instance (Monad m,MonadNondet m) ⇒ MonadNondet (ReaderT r m) where
mzero :: forall a. ReaderT r m a
mzero = (forall a. m a) -> forall a. ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ReaderT r m a -> ReaderT r m a -> ReaderT r m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop (ReaderT r) where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ReaderT r m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftMtop forall a. m a
mtopM = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
_ → m a
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (ReaderT r m) where
mtop :: forall a. ReaderT r m a
mtop = (forall a. m a) -> forall a. ReaderT r m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ReaderT r m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance LiftCont (ReaderT r) where
liftCallCC ∷ ∀ m r'. (Monad m) ⇒ (∀ a. ((a → m r') → m r') → m a) → (∀ a. ((a → ReaderT r m r') → ReaderT r m r') → ReaderT r m a)
liftCallCC :: forall (m :: * -> *) r.
Monad m =>
(forall a. ((a -> m r) -> m r) -> m a)
-> forall a.
((a -> ReaderT r m r) -> ReaderT r m r) -> ReaderT r m a
liftCallCC forall a. ((a -> m r') -> m r') -> m a
callCCM (a -> ReaderT r m r') -> ReaderT r m r'
kk = (r -> m a) -> ReaderT r m a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m a) -> ReaderT r m a) -> (r -> m a) -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ \ r
r →
((a -> m r') -> m r') -> m a
forall a. ((a -> m r') -> m r') -> m a
callCCM (((a -> m r') -> m r') -> m a) -> ((a -> m r') -> m r') -> m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m r'
k ∷ a → m r') →
r -> ReaderT r m r' -> m r'
forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT r
r (ReaderT r m r' -> m r') -> ReaderT r m r' -> m r'
forall a b. (a -> b) -> a -> b
$ (a -> ReaderT r m r') -> ReaderT r m r'
kk ((a -> ReaderT r m r') -> ReaderT r m r')
-> (a -> ReaderT r m r') -> ReaderT r m r'
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
(r -> m r') -> ReaderT r m r'
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m r') -> ReaderT r m r') -> (r -> m r') -> ReaderT r m r'
forall a b. (a -> b) -> a -> b
$ \ r
_ →
a -> m r'
k a
x
liftWithC ∷ ∀ m r'. (Monad m) ⇒ (∀ a. (a → m r') → m a → m r') → (∀ a. (a → ReaderT r m r') → ReaderT r m a → ReaderT r m r')
liftWithC :: forall (m :: * -> *) r.
Monad m =>
(forall a. (a -> m r) -> m a -> m r)
-> forall a. (a -> ReaderT r m r) -> ReaderT r m a -> ReaderT r m r
liftWithC forall a. (a -> m r') -> m a -> m r'
withCM a -> ReaderT r m r'
k ReaderT r m a
xM = (r -> m r') -> ReaderT r m r'
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> m r') -> ReaderT r m r') -> (r -> m r') -> ReaderT r m r'
forall a b. (a -> b) -> a -> b
$ \ r
r →
((a -> m r') -> m a -> m r') -> m a -> (a -> m r') -> m r'
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> m r') -> m a -> m r'
forall a. (a -> m r') -> m a -> m r'
withCM (r -> ReaderT r m a -> m a
forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT r
r ReaderT r m a
xM) ((a -> m r') -> m r') -> (a -> m r') -> m r'
forall a b. (a -> b) -> a -> b
$ \ a
x → r -> ReaderT r m r' -> m r'
forall {k} r (m :: k -> *) (a :: k). r -> ReaderT r m a -> m a
runReaderT r
r (ReaderT r m r' -> m r') -> ReaderT r m r' -> m r'
forall a b. (a -> b) -> a -> b
$ a -> ReaderT r m r'
k a
x
instance (Monad m,MonadCont r' m) ⇒ MonadCont r' (ReaderT r m) where
callCC :: forall a.
((a -> ReaderT r m r') -> ReaderT r m r') -> ReaderT r m a
callCC = (forall a. ((a -> m r') -> m r') -> m a)
-> forall a.
((a -> ReaderT r m r') -> ReaderT r m r') -> ReaderT r m a
forall (m :: * -> *) r.
Monad m =>
(forall a. ((a -> m r) -> m r) -> m a)
-> forall a.
((a -> ReaderT r m r) -> ReaderT r m r) -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftCont t, Monad m) =>
(forall a. ((a -> m r) -> m r) -> m a)
-> forall a. ((a -> t m r) -> t m r) -> t m a
liftCallCC ((a -> m r') -> m r') -> m a
forall a. ((a -> m r') -> m r') -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC
withC :: forall a. (a -> ReaderT r m r') -> ReaderT r m a -> ReaderT r m r'
withC = (forall a. (a -> m r') -> m a -> m r')
-> forall a.
(a -> ReaderT r m r') -> ReaderT r m a -> ReaderT r m r'
forall (m :: * -> *) r.
Monad m =>
(forall a. (a -> m r) -> m a -> m r)
-> forall a. (a -> ReaderT r m r) -> ReaderT r m a -> ReaderT r m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftCont t, Monad m) =>
(forall a. (a -> m r) -> m a -> m r)
-> forall a. (a -> t m r) -> t m a -> t m r
liftWithC (a -> m r') -> m a -> m r'
forall a. (a -> m r') -> m a -> m r'
forall r (m :: * -> *) a. MonadCont r m => (a -> m r) -> m a -> m r
withC
instance (Null o) ⇒ LiftIO (WriterT o) where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → WriterT o m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> WriterT o m a
liftIO forall a. IO a -> m a
ioM IO a
xM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
(o ∧ a) -> m (o ∧ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
forall a. Null a => a
null o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Null o,Monad m,MonadIO m) ⇒ MonadIO (WriterT o m) where
io :: forall a. IO a -> WriterT o m a
io = (forall a. IO a -> m a) -> forall a. IO a -> WriterT o m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> WriterT o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance (Null o) ⇒ LiftReader (WriterT o) where
liftAskL ∷ ∀ m r. (Monad m) ⇒ (∀ r'. r ⟢ r' → m r') → (∀ r'. r ⟢ r' → WriterT o m r')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> WriterT o m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = m (o ∧ r') -> WriterT o m r'
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ r') -> WriterT o m r') -> m (o ∧ r') -> WriterT o m r'
forall a b. (a -> b) -> a -> b
$ do
r'
r ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
(o ∧ r') -> m (o ∧ r')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((o ∧ r') -> m (o ∧ r')) -> (o ∧ r') -> m (o ∧ r')
forall a b. (a -> b) -> a -> b
$ o
forall a. Null a => a
null o -> r' -> o ∧ r'
forall a b. a -> b -> a ∧ b
:* r'
r
liftLocalL ∷ ∀ m r. (Monad m) ⇒ (∀ r' a. r ⟢ r' → r' → m a → m a) → (∀ r' a. r ⟢ r' → r' → WriterT o m a → WriterT o m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> WriterT o m a -> WriterT o m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r WriterT o m a
xM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r' -> m (o ∧ a) -> m (o ∧ a)
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m (o ∧ a) -> m (o ∧ a)) -> m (o ∧ a) -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM
instance (Null o,Monad m,MonadReader r m) ⇒ MonadReader r (WriterT o m) where
askL :: forall r'. (r ⟢ r') -> WriterT o m r'
askL = (forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> WriterT o m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> WriterT o m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> WriterT o m a -> WriterT o m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> WriterT o m a -> WriterT o m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> WriterT o m a -> WriterT o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance (Null o) ⇒ LiftWriter (WriterT o) where
liftTell ∷ ∀ m o'. (Monad m) ⇒ (o' → m ()) → (o' → WriterT o m ())
liftTell :: forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> WriterT o m ()
liftTell o' -> m ()
tellM o'
o' = m (o ∧ ()) -> WriterT o m ()
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ ()) -> WriterT o m ()) -> m (o ∧ ()) -> WriterT o m ()
forall a b. (a -> b) -> a -> b
$ do
o' -> m ()
tellM o'
o'
(o ∧ ()) -> m (o ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
forall a. Null a => a
null o -> () -> o ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
liftHijack ∷ ∀ m o'. (Monad m) ⇒ (∀ a. m a → m (o' ∧ a)) → (∀ a. WriterT o m a → WriterT o m (o' ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. WriterT o m a -> WriterT o m (o ∧ a)
liftHijack forall a. m a -> m (o' ∧ a)
hijackM WriterT o m a
xM = m (o ∧ (o' ∧ a)) -> WriterT o m (o' ∧ a)
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ (o' ∧ a)) -> WriterT o m (o' ∧ a))
-> m (o ∧ (o' ∧ a)) -> WriterT o m (o' ∧ a)
forall a b. (a -> b) -> a -> b
$ do
(o'
o' :* (o
o :* a
a)) ← m (o ∧ a) -> m (o' ∧ (o ∧ a))
forall a. m a -> m (o' ∧ a)
hijackM (m (o ∧ a) -> m (o' ∧ (o ∧ a))) -> m (o ∧ a) -> m (o' ∧ (o ∧ a))
forall a b. (a -> b) -> a -> b
$ WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM
(o ∧ (o' ∧ a)) -> m (o ∧ (o' ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
o o -> (o' ∧ a) -> o ∧ (o' ∧ a)
forall a b. a -> b -> a ∧ b
:* (o'
o' o' -> a -> o' ∧ a
forall a b. a -> b -> a ∧ b
:* a
a))
instance (Null o) ⇒ LiftState (WriterT o) where
liftGet ∷ ∀ m s. (Monad m) ⇒ m s → WriterT o m s
liftGet :: forall (m :: * -> *) s. Monad m => m s -> WriterT o m s
liftGet m s
getM = m (o ∧ s) -> WriterT o m s
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ s) -> WriterT o m s) -> m (o ∧ s) -> WriterT o m s
forall a b. (a -> b) -> a -> b
$ do
s
s ← m s
getM
(o ∧ s) -> m (o ∧ s)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
forall a. Null a => a
null o -> s -> o ∧ s
forall a b. a -> b -> a ∧ b
:* s
s)
liftPut ∷ ∀ m s. (Monad m) ⇒ (s → m ()) → (s → WriterT o m ())
liftPut :: forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> WriterT o m ()
liftPut s -> m ()
putM s
s = m (o ∧ ()) -> WriterT o m ()
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ ()) -> WriterT o m ()) -> m (o ∧ ()) -> WriterT o m ()
forall a b. (a -> b) -> a -> b
$ do
s -> m ()
putM s
s
(o ∧ ()) -> m (o ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (o
forall a. Null a => a
null o -> () -> o ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
instance (Null o,Monad m,MonadState s m) ⇒ MonadState s (WriterT o m) where
get :: WriterT o m s
get = m s -> WriterT o m s
forall (m :: * -> *) s. Monad m => m s -> WriterT o m s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> WriterT o m ()
put = (s -> m ()) -> s -> WriterT o m ()
forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> WriterT o m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail (WriterT o) where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. WriterT o m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftAbort forall a. m a
abortM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT m (o ∧ a)
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. WriterT o m a → WriterT o m a → WriterT o m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
liftTry forall a. m a -> m a -> m a
tryM WriterT o m a
xM₁ WriterT o m a
xM₂ = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ m (o ∧ a) -> m (o ∧ a) -> m (o ∧ a)
forall a. m a -> m a -> m a
tryM (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₁) (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₂)
instance (Monad m,MonadFail m) ⇒ MonadFail (WriterT o m) where
abort :: forall a. WriterT o m a
abort = (forall a. m a) -> forall a. WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError (WriterT o) where
liftThrow ∷ ∀ m e. (Monad m) ⇒ (∀ a. e → m a) → (∀ a. e → WriterT o m a)
liftThrow :: forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> WriterT o m a
liftThrow forall a. e -> m a
throwM e
e = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ e -> m (o ∧ a)
forall a. e -> m a
throwM e
e
liftCatch ∷ ∀ m e. (Monad m) ⇒ (∀ a. m a → (e → m a) → m a) → (∀ a. WriterT o m a → (e → WriterT o m a) → WriterT o m a)
liftCatch :: forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. WriterT o m a -> (e -> WriterT o m a) -> WriterT o m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM WriterT o m a
xM e -> WriterT o m a
k = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ m (o ∧ a) -> (e -> m (o ∧ a)) -> m (o ∧ a)
forall a. m a -> (e -> m a) -> m a
catchM (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM) ((e -> m (o ∧ a)) -> m (o ∧ a)) -> (e -> m (o ∧ a)) -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ e
e → WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (WriterT o m a -> m (o ∧ a)) -> WriterT o m a -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ e -> WriterT o m a
k e
e
instance (Monad m,MonadError e m) ⇒ MonadError e (WriterT o m) where
throw :: forall a. e -> WriterT o m a
throw = (forall a. e -> m a) -> forall a. e -> WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> WriterT o m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. WriterT o m a -> (e -> WriterT o m a) -> WriterT o m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. WriterT o m a -> (e -> WriterT o m a) -> WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. WriterT o m a -> (e -> WriterT o m a) -> WriterT o m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay (WriterT o) where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> WriterT o m a) -> WriterT o m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> WriterT o m a
xMU = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ (() -> m (o ∧ a)) -> m (o ∧ a)
forall a. (() -> m a) -> m a
delayM ((() -> m (o ∧ a)) -> m (o ∧ a)) -> (() -> m (o ∧ a)) -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ () → WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (WriterT o m a -> m (o ∧ a)) -> WriterT o m a -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ () -> WriterT o m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (WriterT o m) where
delay :: forall a. (() -> WriterT o m a) -> WriterT o m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> WriterT o m a) -> WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> WriterT o m a) -> WriterT o m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet (WriterT o) where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. WriterT o m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftMzero forall a. m a
mzeroM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT m (o ∧ a)
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. WriterT o m a → WriterT o m a → WriterT o m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
liftMplus forall a. m a -> m a -> m a
mplusM WriterT o m a
xM₁ WriterT o m a
xM₂ = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ m (o ∧ a) -> m (o ∧ a) -> m (o ∧ a)
forall a. m a -> m a -> m a
mplusM (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₁) (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM₂)
instance (Monad m,MonadNondet m) ⇒ MonadNondet (WriterT o m) where
mzero :: forall a. WriterT o m a
mzero = (forall a. m a) -> forall a. WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. WriterT o m a -> WriterT o m a -> WriterT o m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop (WriterT o) where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. WriterT o m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftMtop forall a. m a
mtopM = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT m (o ∧ a)
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (WriterT o m) where
mtop :: forall a. WriterT o m a
mtop = (forall a. m a) -> forall a. WriterT o m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. WriterT o m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (Monoid o,Monad m,MonadCont (o ∧ r) m) ⇒ MonadCont r (WriterT o m) where
callCC ∷ ∀ a. ((a → WriterT o m r) → WriterT o m r) → WriterT o m a
callCC :: forall a. ((a -> WriterT o m r) -> WriterT o m r) -> WriterT o m a
callCC (a -> WriterT o m r) -> WriterT o m r
kk = m (o ∧ a) -> WriterT o m a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ a) -> WriterT o m a) -> m (o ∧ a) -> WriterT o m a
forall a b. (a -> b) -> a -> b
$ (((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> m (o ∧ a)
forall a. ((a -> m (o ∧ r)) -> m (o ∧ r)) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC ((((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> m (o ∧ a))
-> (((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ ((o ∧ a) -> m (o ∧ r)
k ∷ (o ∧ a) → m (o ∧ r)) →
WriterT o m r -> m (o ∧ r)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (WriterT o m r -> m (o ∧ r)) -> WriterT o m r -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ (a -> WriterT o m r) -> WriterT o m r
kk ((a -> WriterT o m r) -> WriterT o m r)
-> (a -> WriterT o m r) -> WriterT o m r
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
m (o ∧ r) -> WriterT o m r
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ r) -> WriterT o m r) -> m (o ∧ r) -> WriterT o m r
forall a b. (a -> b) -> a -> b
$ (o ∧ a) -> m (o ∧ r)
k ((o ∧ a) -> m (o ∧ r)) -> (o ∧ a) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ o
forall a. Null a => a
null o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x
withC ∷ ∀ a. (a → WriterT o m r) → WriterT o m a → WriterT o m r
withC :: forall a. (a -> WriterT o m r) -> WriterT o m a -> WriterT o m r
withC a -> WriterT o m r
k WriterT o m a
xM = m (o ∧ r) -> WriterT o m r
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (m (o ∧ r) -> WriterT o m r) -> m (o ∧ r) -> WriterT o m r
forall a b. (a -> b) -> a -> b
$
m (o ∧ a) -> ((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)
forall (m :: * -> *) u a.
(Monad m, MonadCont u m) =>
m a -> (a -> m u) -> m u
withCOn (WriterT o m a -> m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT WriterT o m a
xM) (((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r))
-> ((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ \ (o
o₁ :* a
x ∷ o ∧ a) → do
o
o₂ :* r
r ← WriterT o m r -> m (o ∧ r)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (WriterT o m r -> m (o ∧ r)) -> WriterT o m r -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ a -> WriterT o m r
k a
x
(o ∧ r) -> m (o ∧ r)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((o ∧ r) -> m (o ∧ r)) -> (o ∧ r) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ (o
o₁ o -> o -> o
forall a. Append a => a -> a -> a
⧺ o
o₂) o -> r -> o ∧ r
forall a b. a -> b -> a ∧ b
:* r
r
instance LiftIO (StateT s) where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → StateT s m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> StateT s m a
liftIO forall a. IO a -> m a
ioM IO a
xM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
(s ∧ a) -> m (s ∧ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> a -> s ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Monad m,MonadIO m) ⇒ MonadIO (StateT s m) where
io :: forall a. IO a -> StateT s m a
io = (forall a. IO a -> m a) -> forall a. IO a -> StateT s m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader (StateT s) where
liftAskL ∷ ∀ m r. (Monad m) ⇒ (∀ r'. r ⟢ r' → m r') → (∀ r'. r ⟢ r' → StateT s m r')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> StateT s m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = (s -> m (s ∧ r')) -> StateT s m r'
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ r')) -> StateT s m r')
-> (s -> m (s ∧ r')) -> StateT s m r'
forall a b. (a -> b) -> a -> b
$ \ s
s → do
r'
r ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
(s ∧ r') -> m (s ∧ r')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((s ∧ r') -> m (s ∧ r')) -> (s ∧ r') -> m (s ∧ r')
forall a b. (a -> b) -> a -> b
$ s
s s -> r' -> s ∧ r'
forall a b. a -> b -> a ∧ b
:* r'
r
liftLocalL ∷ ∀ m r. (Monad m) ⇒ (∀ r' a. r ⟢ r' → r' → m a → m a) → (∀ r' a. r ⟢ r' → r' → StateT s m a → StateT s m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> StateT s m a -> StateT s m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r StateT s m a
xM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → (r ⟢ r') -> r' -> m (s ∧ a) -> m (s ∧ a)
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m (s ∧ a) -> m (s ∧ a)) -> m (s ∧ a) -> m (s ∧ a)
forall a b. (a -> b) -> a -> b
$ StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM s
s
instance (Monad m,MonadReader r m) ⇒ MonadReader r (StateT s m) where
askL :: forall r'. (r ⟢ r') -> StateT s m r'
askL = (forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> StateT s m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> StateT s m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> StateT s m a -> StateT s m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> StateT s m a -> StateT s m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> StateT s m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance LiftWriter (StateT s) where
liftTell ∷ ∀ m o. (Monad m) ⇒ (o → m ()) → (o → StateT s m ())
liftTell :: forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> StateT s m ()
liftTell o -> m ()
tellM o
o = (s -> m (s ∧ ())) -> StateT s m ()
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ ())) -> StateT s m ())
-> (s -> m (s ∧ ())) -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ \ s
s → do
o -> m ()
tellM o
o
(s ∧ ()) -> m (s ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> () -> s ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
liftHijack ∷ ∀ m o. (Monad m) ⇒ (∀ a. m a → m (o ∧ a)) → (∀ a. StateT s m a → StateT s m (o ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. StateT s m a -> StateT s m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM StateT s m a
xM = (s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a)
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a))
-> (s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ s
s → do
(o
o :* (s
s' :* a
x)) ← m (s ∧ a) -> m (o ∧ (s ∧ a))
forall a. m a -> m (o ∧ a)
hijackM (m (s ∧ a) -> m (o ∧ (s ∧ a))) -> m (s ∧ a) -> m (o ∧ (s ∧ a))
forall a b. (a -> b) -> a -> b
$ StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM s
s
(s ∧ (o ∧ a)) -> m (s ∧ (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s' s -> (o ∧ a) -> s ∧ (o ∧ a)
forall a b. a -> b -> a ∧ b
:* (o
o o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x))
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (StateT s m) where
tell :: o -> StateT s m ()
tell = (o -> m ()) -> o -> StateT s m ()
forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> StateT s m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. StateT s m a -> StateT s m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. StateT s m a -> StateT s m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. StateT s m a -> StateT s m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState (StateT s) where
liftGet ∷ ∀ m s'. (Monad m) ⇒ m s' → StateT s m s'
liftGet :: forall (m :: * -> *) s. Monad m => m s -> StateT s m s
liftGet m s'
getM = (s -> m (s ∧ s')) -> StateT s m s'
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ s')) -> StateT s m s')
-> (s -> m (s ∧ s')) -> StateT s m s'
forall a b. (a -> b) -> a -> b
$ \ s
s → do
s'
s' ← m s'
getM
(s ∧ s') -> m (s ∧ s')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> s' -> s ∧ s'
forall a b. a -> b -> a ∧ b
:* s'
s')
liftPut ∷ ∀ m s'. (Monad m) ⇒ (s' → m ()) → s' → StateT s m ()
liftPut :: forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> StateT s m ()
liftPut s' -> m ()
putM s'
s' = (s -> m (s ∧ ())) -> StateT s m ()
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ ())) -> StateT s m ())
-> (s -> m (s ∧ ())) -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ \ s
s → do
s' -> m ()
putM s'
s'
(s ∧ ()) -> m (s ∧ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s s -> () -> s ∧ ()
forall a b. a -> b -> a ∧ b
:* ())
instance LiftFail (StateT s) where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. StateT s m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftAbort forall a. m a
abortM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
_ → m (s ∧ a)
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. StateT s m a → StateT s m a → StateT s m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
liftTry forall a. m a -> m a -> m a
tryM StateT s m a
xM₁ StateT s m a
xM₂ = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → m (s ∧ a) -> m (s ∧ a) -> m (s ∧ a)
forall a. m a -> m a -> m a
tryM (StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₁ s
s) (StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₂ s
s)
instance (Monad m,MonadFail m) ⇒ MonadFail (StateT s m) where
abort :: forall a. StateT s m a
abort = (forall a. m a) -> forall a. StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. StateT s m a -> StateT s m a -> StateT s m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError (StateT s) where
liftThrow ∷ ∀ m e. (Monad m) ⇒ (∀ a. e → m a) → (∀ a. e → StateT s m a)
liftThrow :: forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> StateT s m a
liftThrow forall a. e -> m a
throwM e
e = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
_ → e -> m (s ∧ a)
forall a. e -> m a
throwM e
e
liftCatch ∷ ∀ m e. (Monad m) ⇒ (∀ a. m a → (e → m a) → m a) → (∀ a. StateT s m a → (e → StateT s m a) → StateT s m a)
liftCatch :: forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. StateT s m a -> (e -> StateT s m a) -> StateT s m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM StateT s m a
xM e -> StateT s m a
k = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → m (s ∧ a) -> (e -> m (s ∧ a)) -> m (s ∧ a)
forall a. m a -> (e -> m a) -> m a
catchM (StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM s
s) (\ e
e → StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT (e -> StateT s m a
k e
e) s
s)
instance (Monad m,MonadError e m) ⇒ MonadError e (StateT s m) where
throw :: forall a. e -> StateT s m a
throw = (forall a. e -> m a) -> forall a. e -> StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> StateT s m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. StateT s m a -> (e -> StateT s m a) -> StateT s m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. StateT s m a -> (e -> StateT s m a) -> StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. StateT s m a -> (e -> StateT s m a) -> StateT s m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay (StateT s) where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> StateT s m a) -> StateT s m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> StateT s m a
xMU = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → (() -> m (s ∧ a)) -> m (s ∧ a)
forall a. (() -> m a) -> m a
delayM ((() -> m (s ∧ a)) -> m (s ∧ a)) -> (() -> m (s ∧ a)) -> m (s ∧ a)
forall a b. (a -> b) -> a -> b
$ \ () → s -> StateT s m a -> m (s ∧ a)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s (StateT s m a -> m (s ∧ a)) -> StateT s m a -> m (s ∧ a)
forall a b. (a -> b) -> a -> b
$ () -> StateT s m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (StateT s m) where
delay :: forall a. (() -> StateT s m a) -> StateT s m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> StateT s m a) -> StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> StateT s m a) -> StateT s m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet (StateT s) where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. StateT s m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftMzero forall a. m a
mzeroM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
_ → m (s ∧ a)
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. StateT s m a → StateT s m a → StateT s m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
liftMplus forall a. m a -> m a -> m a
mplusM StateT s m a
xM₁ StateT s m a
xM₂ = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s → m (s ∧ a) -> m (s ∧ a) -> m (s ∧ a)
forall a. m a -> m a -> m a
mplusM (StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₁ s
s) (StateT s m a -> s -> m (s ∧ a)
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT StateT s m a
xM₂ s
s)
instance (Monad m,MonadNondet m) ⇒ MonadNondet (StateT s m) where
mzero :: forall a. StateT s m a
mzero = (forall a. m a) -> forall a. StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. StateT s m a -> StateT s m a -> StateT s m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. StateT s m a -> StateT s m a -> StateT s m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop (StateT s) where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. StateT s m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftMtop forall a. m a
mtopM = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
_ → m (s ∧ a)
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (StateT s m) where
mtop :: forall a. StateT s m a
mtop = (forall a. m a) -> forall a. StateT s m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. StateT s m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (Monad m,MonadCont (s ∧ u) m) ⇒ MonadCont u (StateT s m) where
callCC ∷ ∀ a. ((a → StateT s m u) → StateT s m u) → StateT s m a
callCC :: forall a. ((a -> StateT s m u) -> StateT s m u) -> StateT s m a
callCC (a -> StateT s m u) -> StateT s m u
ff = (s -> m (s ∧ a)) -> StateT s m a
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ a)) -> StateT s m a)
-> (s -> m (s ∧ a)) -> StateT s m a
forall a b. (a -> b) -> a -> b
$ \ s
s₁ →
(((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u)) -> m (s ∧ a)
forall a. ((a -> m (s ∧ u)) -> m (s ∧ u)) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC ((((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u)) -> m (s ∧ a))
-> (((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u)) -> m (s ∧ a)
forall a b. (a -> b) -> a -> b
$ \ ((s ∧ a) -> m (s ∧ u)
𝓀 ∷ (s ∧ a) → m (s ∧ u)) →
s -> StateT s m u -> m (s ∧ u)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s₁ (StateT s m u -> m (s ∧ u)) -> StateT s m u -> m (s ∧ u)
forall a b. (a -> b) -> a -> b
$ (a -> StateT s m u) -> StateT s m u
ff ((a -> StateT s m u) -> StateT s m u)
-> (a -> StateT s m u) -> StateT s m u
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
(s -> m (s ∧ u)) -> StateT s m u
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ u)) -> StateT s m u)
-> (s -> m (s ∧ u)) -> StateT s m u
forall a b. (a -> b) -> a -> b
$ \ s
s₂ →
(s ∧ a) -> m (s ∧ u)
𝓀 ((s ∧ a) -> m (s ∧ u)) -> (s ∧ a) -> m (s ∧ u)
forall a b. (a -> b) -> a -> b
$ s
s₂ s -> a -> s ∧ a
forall a b. a -> b -> a ∧ b
:* a
x
withC ∷ ∀ a. (a → StateT s m u) → StateT s m a → StateT s m u
withC :: forall a. (a -> StateT s m u) -> StateT s m a -> StateT s m u
withC a -> StateT s m u
f StateT s m a
xM = (s -> m (s ∧ u)) -> StateT s m u
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ u)) -> StateT s m u)
-> (s -> m (s ∧ u)) -> StateT s m u
forall a b. (a -> b) -> a -> b
$ \ s
s₁ →
m (s ∧ a) -> ((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u)
forall (m :: * -> *) u a.
(Monad m, MonadCont u m) =>
m a -> (a -> m u) -> m u
withCOn (s -> StateT s m a -> m (s ∧ a)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s₁ StateT s m a
xM) (((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u))
-> ((s ∧ a) -> m (s ∧ u)) -> m (s ∧ u)
forall a b. (a -> b) -> a -> b
$ \ (s
s₂ :* a
x ∷ s ∧ a) →
s -> StateT s m u -> m (s ∧ u)
forall s (m :: * -> *) a. s -> StateT s m a -> m (s ∧ a)
runStateT s
s₂ (StateT s m u -> m (s ∧ u)) -> StateT s m u -> m (s ∧ u)
forall a b. (a -> b) -> a -> b
$ a -> StateT s m u
f a
x
instance LiftIO FailT where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → FailT m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> FailT m a
liftIO forall a. IO a -> m a
ioM IO a
xM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
𝑂 a -> m (𝑂 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 a -> m (𝑂 a)) -> 𝑂 a -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ a -> 𝑂 a
forall a. a -> 𝑂 a
Some a
x
instance (Monad m,MonadIO m) ⇒ MonadIO (FailT m) where
io :: forall a. IO a -> FailT m a
io = (forall a. IO a -> m a) -> forall a. IO a -> FailT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> FailT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader FailT where
liftAskL ∷ ∀ m r. (Monad m) ⇒ (∀ r'. r ⟢ r' → m r') → (∀ r'. r ⟢ r' → FailT m r')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> FailT m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = m (𝑂 r') -> FailT m r'
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 r') -> FailT m r') -> m (𝑂 r') -> FailT m r'
forall a b. (a -> b) -> a -> b
$ do
r'
r ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
𝑂 r' -> m (𝑂 r')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 r' -> m (𝑂 r')) -> 𝑂 r' -> m (𝑂 r')
forall a b. (a -> b) -> a -> b
$ r' -> 𝑂 r'
forall a. a -> 𝑂 a
Some r'
r
liftLocalL ∷ ∀ m r. (Monad m) ⇒ (∀ r' a. r ⟢ r' → r' → m a → m a) → (∀ r' a. r ⟢ r' → r' → FailT m a → FailT m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> FailT m a -> FailT m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r FailT m a
xM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r' -> m (𝑂 a) -> m (𝑂 a)
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m (𝑂 a) -> m (𝑂 a)) -> m (𝑂 a) -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM
instance (Monad m,MonadReader r m) ⇒ MonadReader r (FailT m) where
askL :: forall r'. (r ⟢ r') -> FailT m r'
askL = (forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> FailT m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> FailT m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> FailT m a -> FailT m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> FailT m a -> FailT m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> FailT m a -> FailT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance LiftWriter FailT where
liftTell ∷ ∀ m o. (Monad m) ⇒ (o → m ()) → (o → FailT m ())
liftTell :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> FailT m ()
liftTell o -> m ()
tellM o
o = m (𝑂 ()) -> FailT m ()
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 ()) -> FailT m ()) -> m (𝑂 ()) -> FailT m ()
forall a b. (a -> b) -> a -> b
$ do
o -> m ()
tellM o
o
𝑂 () -> m (𝑂 ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 () -> m (𝑂 ())) -> 𝑂 () -> m (𝑂 ())
forall a b. (a -> b) -> a -> b
$ () -> 𝑂 ()
forall a. a -> 𝑂 a
Some ()
liftHijack ∷ ∀ m o. (Monad m) ⇒ (∀ a. m a → m (o ∧ a)) → (∀ a. FailT m a → FailT m (o ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. FailT m a -> FailT m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM FailT m a
xM = m (𝑂 (o ∧ a)) -> FailT m (o ∧ a)
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 (o ∧ a)) -> FailT m (o ∧ a))
-> m (𝑂 (o ∧ a)) -> FailT m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ do
(o
o :* 𝑂 a
xO) ← m (𝑂 a) -> m (o ∧ 𝑂 a)
forall a. m a -> m (o ∧ a)
hijackM (m (𝑂 a) -> m (o ∧ 𝑂 a)) -> m (𝑂 a) -> m (o ∧ 𝑂 a)
forall a b. (a -> b) -> a -> b
$ FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM
case 𝑂 a
xO of
𝑂 a
None → 𝑂 (o ∧ a) -> m (𝑂 (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return 𝑂 (o ∧ a)
forall a. 𝑂 a
None
Some a
x → 𝑂 (o ∧ a) -> m (𝑂 (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 (o ∧ a) -> m (𝑂 (o ∧ a))) -> 𝑂 (o ∧ a) -> m (𝑂 (o ∧ a))
forall a b. (a -> b) -> a -> b
$ (o ∧ a) -> 𝑂 (o ∧ a)
forall a. a -> 𝑂 a
Some (o
o o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (FailT m) where
tell :: o -> FailT m ()
tell = (o -> m ()) -> o -> FailT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> FailT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. FailT m a -> FailT m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. FailT m a -> FailT m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. FailT m a -> FailT m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState FailT where
liftGet ∷ ∀ m s. (Monad m) ⇒ m s → FailT m s
liftGet :: forall (m :: * -> *) a. Monad m => m a -> FailT m a
liftGet m s
getM = m (𝑂 s) -> FailT m s
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 s) -> FailT m s) -> m (𝑂 s) -> FailT m s
forall a b. (a -> b) -> a -> b
$ do
s
s ← m s
getM
𝑂 s -> m (𝑂 s)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 s -> m (𝑂 s)) -> 𝑂 s -> m (𝑂 s)
forall a b. (a -> b) -> a -> b
$ s -> 𝑂 s
forall a. a -> 𝑂 a
Some s
s
liftPut ∷ ∀ m s. (Monad m) ⇒ (s → m ()) → (s → FailT m ())
liftPut :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> FailT m ()
liftPut s -> m ()
putM s
s = m (𝑂 ()) -> FailT m ()
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 ()) -> FailT m ()) -> m (𝑂 ()) -> FailT m ()
forall a b. (a -> b) -> a -> b
$ do
s -> m ()
putM s
s
𝑂 () -> m (𝑂 ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑂 () -> m (𝑂 ())) -> 𝑂 () -> m (𝑂 ())
forall a b. (a -> b) -> a -> b
$ () -> 𝑂 ()
forall a. a -> 𝑂 a
Some ()
instance (Monad m,MonadState s m) ⇒ MonadState s (FailT m) where
get :: FailT m s
get = m s -> FailT m s
forall (m :: * -> *) a. Monad m => m a -> FailT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> FailT m ()
put = (s -> m ()) -> s -> FailT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> FailT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail FailT where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. FailT m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. FailT m a
liftAbort forall a. m a
abortM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a)
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. FailT m a → FailT m a → FailT m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. FailT m a -> FailT m a -> FailT m a
liftTry forall a. m a -> m a -> m a
tryM FailT m a
xM₁ FailT m a
xM₂ = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a) -> m (𝑂 a) -> m (𝑂 a)
forall a. m a -> m a -> m a
tryM (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₁) (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₂)
instance LiftError FailT where
liftThrow ∷ ∀ e m. (Monad m) ⇒ (∀ a. e → m a) → (∀ a. e → FailT m a)
liftThrow :: forall e (m :: * -> *).
Monad m =>
(forall a. e -> m a) -> forall a. e -> FailT m a
liftThrow forall a. e -> m a
throwM e
e = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ e -> m (𝑂 a)
forall a. e -> m a
throwM e
e
liftCatch ∷ ∀ e m. (Monad m) ⇒ (∀ a. m a → (e → m a) → m a) → (∀ a. FailT m a → (e → FailT m a) → FailT m a)
liftCatch :: forall e (m :: * -> *).
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. FailT m a -> (e -> FailT m a) -> FailT m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM FailT m a
xM e -> FailT m a
k = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a) -> (e -> m (𝑂 a)) -> m (𝑂 a)
forall a. m a -> (e -> m a) -> m a
catchM (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM) ((e -> m (𝑂 a)) -> m (𝑂 a)) -> (e -> m (𝑂 a)) -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ \ e
e → FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT m a -> m (𝑂 a)) -> FailT m a -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ e -> FailT m a
k e
e
instance (Monad m,MonadError e m) ⇒ MonadError e (FailT m) where
throw :: forall a. e -> FailT m a
throw = (forall a. e -> m a) -> forall a. e -> FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> FailT m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. FailT m a -> (e -> FailT m a) -> FailT m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. FailT m a -> (e -> FailT m a) -> FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. FailT m a -> (e -> FailT m a) -> FailT m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay FailT where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> FailT m a) -> FailT m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> FailT m a
xMU = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ (() -> m (𝑂 a)) -> m (𝑂 a)
forall a. (() -> m a) -> m a
delayM ((() -> m (𝑂 a)) -> m (𝑂 a)) -> (() -> m (𝑂 a)) -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ \ () → FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT m a -> m (𝑂 a)) -> FailT m a -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ () -> FailT m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (FailT m) where
delay :: forall a. (() -> FailT m a) -> FailT m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> FailT m a) -> FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> FailT m a) -> FailT m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet FailT where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. FailT m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. FailT m a
liftMzero forall a. m a
mzeroM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a)
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. FailT m a → FailT m a → FailT m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. FailT m a -> FailT m a -> FailT m a
liftMplus forall a. m a -> m a -> m a
mplusM FailT m a
xM₁ FailT m a
xM₂ = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a) -> m (𝑂 a) -> m (𝑂 a)
forall a. m a -> m a -> m a
mplusM (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₁) (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM₂)
instance (Monad m,MonadNondet m) ⇒ MonadNondet (FailT m) where
mzero :: forall a. FailT m a
mzero = (forall a. m a) -> forall a. FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. FailT m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. FailT m a -> FailT m a -> FailT m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. FailT m a -> FailT m a -> FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. FailT m a -> FailT m a -> FailT m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop FailT where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. FailT m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. FailT m a
liftMtop forall a. m a
mtopM = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$ m (𝑂 a)
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (FailT m) where
mtop :: forall a. FailT m a
mtop = (forall a. m a) -> forall a. FailT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. FailT m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (Monad m,MonadCont (𝑂 r) m) ⇒ MonadCont r (FailT m) where
callCC ∷ ∀ a. ((a → FailT m r) → FailT m r) → FailT m a
callCC :: forall a. ((a -> FailT m r) -> FailT m r) -> FailT m a
callCC (a -> FailT m r) -> FailT m r
kk = m (𝑂 a) -> FailT m a
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 a) -> FailT m a) -> m (𝑂 a) -> FailT m a
forall a b. (a -> b) -> a -> b
$
((𝑂 a -> m (𝑂 r)) -> m (𝑂 r)) -> m (𝑂 a)
forall a. ((a -> m (𝑂 r)) -> m (𝑂 r)) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC (((𝑂 a -> m (𝑂 r)) -> m (𝑂 r)) -> m (𝑂 a))
-> ((𝑂 a -> m (𝑂 r)) -> m (𝑂 r)) -> m (𝑂 a)
forall a b. (a -> b) -> a -> b
$ \ (𝑂 a -> m (𝑂 r)
k ∷ 𝑂 a → m (𝑂 r)) →
FailT m r -> m (𝑂 r)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT m r -> m (𝑂 r)) -> FailT m r -> m (𝑂 r)
forall a b. (a -> b) -> a -> b
$ (a -> FailT m r) -> FailT m r
kk ((a -> FailT m r) -> FailT m r) -> (a -> FailT m r) -> FailT m r
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
m (𝑂 r) -> FailT m r
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 r) -> FailT m r) -> m (𝑂 r) -> FailT m r
forall a b. (a -> b) -> a -> b
$ 𝑂 a -> m (𝑂 r)
k (𝑂 a -> m (𝑂 r)) -> 𝑂 a -> m (𝑂 r)
forall a b. (a -> b) -> a -> b
$ a -> 𝑂 a
forall a. a -> 𝑂 a
Some a
x
withC ∷ ∀ a. (a → FailT m r) → FailT m a → FailT m r
withC :: forall a. (a -> FailT m r) -> FailT m a -> FailT m r
withC a -> FailT m r
k FailT m a
xM = m (𝑂 r) -> FailT m r
forall (m :: * -> *) a. m (𝑂 a) -> FailT m a
FailT (m (𝑂 r) -> FailT m r) -> m (𝑂 r) -> FailT m r
forall a b. (a -> b) -> a -> b
$
m (𝑂 a) -> (𝑂 a -> m (𝑂 r)) -> m (𝑂 r)
forall (m :: * -> *) u a.
(Monad m, MonadCont u m) =>
m a -> (a -> m u) -> m u
withCOn (FailT m a -> m (𝑂 a)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT FailT m a
xM) ((𝑂 a -> m (𝑂 r)) -> m (𝑂 r)) -> (𝑂 a -> m (𝑂 r)) -> m (𝑂 r)
forall a b. (a -> b) -> a -> b
$ \ (𝑂 a
xO ∷ 𝑂 a) → case 𝑂 a
xO of
𝑂 a
None → 𝑂 r -> m (𝑂 r)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return 𝑂 r
forall a. 𝑂 a
None
Some a
x → FailT m r -> m (𝑂 r)
forall (m :: * -> *) a. FailT m a -> m (𝑂 a)
unFailT (FailT m r -> m (𝑂 r)) -> FailT m r -> m (𝑂 r)
forall a b. (a -> b) -> a -> b
$ a -> FailT m r
k a
x
instance LiftIO (ErrorT e) where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → ErrorT e m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ErrorT e m a
liftIO forall a. IO a -> m a
ioM IO a
xM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
(e ∨ a) -> m (e ∨ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ a) -> m (e ∨ a)) -> (e ∨ a) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ a -> e ∨ a
forall a b. b -> a ∨ b
Inr a
x
instance (Monad m,MonadIO m) ⇒ MonadIO (ErrorT e m) where
io :: forall a. IO a -> ErrorT e m a
io = (forall a. IO a -> m a) -> forall a. IO a -> ErrorT e m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ErrorT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader (ErrorT e) where
liftAskL ∷ ∀ m r. (Monad m) ⇒ (∀ r'. r ⟢ r' → m r') → (∀ r'. r ⟢ r' → ErrorT e m r')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> ErrorT e m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = m (e ∨ r') -> ErrorT e m r'
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ r') -> ErrorT e m r') -> m (e ∨ r') -> ErrorT e m r'
forall a b. (a -> b) -> a -> b
$ do
r'
r ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
(e ∨ r') -> m (e ∨ r')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ r') -> m (e ∨ r')) -> (e ∨ r') -> m (e ∨ r')
forall a b. (a -> b) -> a -> b
$ r' -> e ∨ r'
forall a b. b -> a ∨ b
Inr r'
r
liftLocalL ∷ ∀ m r. (Monad m) ⇒ (∀ r' a. r ⟢ r' → r' → m a → m a) → (∀ r' a. r ⟢ r' → r' → ErrorT e m a → ErrorT e m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> ErrorT e m a -> ErrorT e m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r ErrorT e m a
xM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r' -> m (e ∨ a) -> m (e ∨ a)
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m (e ∨ a) -> m (e ∨ a)) -> m (e ∨ a) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM
instance (Monad m,MonadReader r m) ⇒ MonadReader r (ErrorT e m) where
askL :: forall r'. (r ⟢ r') -> ErrorT e m r'
askL = (forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> ErrorT e m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> ErrorT e m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> ErrorT e m a -> ErrorT e m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> ErrorT e m a -> ErrorT e m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> ErrorT e m a -> ErrorT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance LiftWriter (ErrorT e) where
liftTell ∷ ∀ m o. (Monad m) ⇒ (o → m ()) → (o → ErrorT e m ())
liftTell :: forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> ErrorT e m ()
liftTell o -> m ()
tellM o
o = m (e ∨ ()) -> ErrorT e m ()
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ ()) -> ErrorT e m ()) -> m (e ∨ ()) -> ErrorT e m ()
forall a b. (a -> b) -> a -> b
$ do
o -> m ()
tellM o
o
(e ∨ ()) -> m (e ∨ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ ()) -> m (e ∨ ())) -> (e ∨ ()) -> m (e ∨ ())
forall a b. (a -> b) -> a -> b
$ () -> e ∨ ()
forall a b. b -> a ∨ b
Inr ()
liftHijack ∷ ∀ m o. (Monad m) ⇒ (∀ a. m a → m (o ∧ a)) → (∀ a. ErrorT e m a → ErrorT e m (o ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. ErrorT e m a -> ErrorT e m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM ErrorT e m a
xM = m (e ∨ (o ∧ a)) -> ErrorT e m (o ∧ a)
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ (o ∧ a)) -> ErrorT e m (o ∧ a))
-> m (e ∨ (o ∧ a)) -> ErrorT e m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ do
(o
o :* e ∨ a
xE) ← m (e ∨ a) -> m (o ∧ (e ∨ a))
forall a. m a -> m (o ∧ a)
hijackM (m (e ∨ a) -> m (o ∧ (e ∨ a))) -> m (e ∨ a) -> m (o ∧ (e ∨ a))
forall a b. (a -> b) -> a -> b
$ ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM
case e ∨ a
xE of
Inl e
e → (e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a)))
-> (e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a))
forall a b. (a -> b) -> a -> b
$ e -> e ∨ (o ∧ a)
forall a b. a -> a ∨ b
Inl e
e
Inr a
x → (e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a)))
-> (e ∨ (o ∧ a)) -> m (e ∨ (o ∧ a))
forall a b. (a -> b) -> a -> b
$ (o ∧ a) -> e ∨ (o ∧ a)
forall a b. b -> a ∨ b
Inr (o
o o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x)
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (ErrorT e m) where
tell :: o -> ErrorT e m ()
tell = (o -> m ()) -> o -> ErrorT e m ()
forall (m :: * -> *) o.
Monad m =>
(o -> m ()) -> o -> ErrorT e m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. ErrorT e m a -> ErrorT e m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. ErrorT e m a -> ErrorT e m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. ErrorT e m a -> ErrorT e m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState (ErrorT e) where
liftGet ∷ ∀ m s. (Monad m) ⇒ m s → ErrorT e m s
liftGet :: forall (m :: * -> *) s. Monad m => m s -> ErrorT e m s
liftGet m s
getM = m (e ∨ s) -> ErrorT e m s
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ s) -> ErrorT e m s) -> m (e ∨ s) -> ErrorT e m s
forall a b. (a -> b) -> a -> b
$ do
s
s ← m s
getM
(e ∨ s) -> m (e ∨ s)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ s) -> m (e ∨ s)) -> (e ∨ s) -> m (e ∨ s)
forall a b. (a -> b) -> a -> b
$ s -> e ∨ s
forall a b. b -> a ∨ b
Inr s
s
liftPut ∷ ∀ m s. (Monad m) ⇒ (s → m ()) → (s → ErrorT e m ())
liftPut :: forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> ErrorT e m ()
liftPut s -> m ()
putM s
s = m (e ∨ ()) -> ErrorT e m ()
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ ()) -> ErrorT e m ()) -> m (e ∨ ()) -> ErrorT e m ()
forall a b. (a -> b) -> a -> b
$ do
s -> m ()
putM s
s
(e ∨ ()) -> m (e ∨ ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ ()) -> m (e ∨ ())) -> (e ∨ ()) -> m (e ∨ ())
forall a b. (a -> b) -> a -> b
$ () -> e ∨ ()
forall a b. b -> a ∨ b
Inr ()
instance (Monad m,MonadState s m) ⇒ MonadState s (ErrorT e m) where
get :: ErrorT e m s
get = m s -> ErrorT e m s
forall (m :: * -> *) s. Monad m => m s -> ErrorT e m s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> ErrorT e m ()
put = (s -> m ()) -> s -> ErrorT e m ()
forall (m :: * -> *) s.
Monad m =>
(s -> m ()) -> s -> ErrorT e m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail (ErrorT e) where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ErrorT e m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftAbort forall a. m a
abortM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a)
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. ErrorT e m a → ErrorT e m a → ErrorT e m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
liftTry forall a. m a -> m a -> m a
tryM ErrorT e m a
xM₁ ErrorT e m a
xM₂ = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a) -> m (e ∨ a) -> m (e ∨ a)
forall a. m a -> m a -> m a
tryM (ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₁) (ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₂)
instance (Monad m,MonadFail m) ⇒ MonadFail (ErrorT e m) where
abort :: forall a. ErrorT e m a
abort = (forall a. m a) -> forall a. ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError (ErrorT e) where
liftThrow ∷ ∀ e' m. (Monad m) ⇒ (∀ a. e' → m a) → (∀ a. e' → ErrorT e m a)
liftThrow :: forall e' (m :: * -> *).
Monad m =>
(forall a. e' -> m a) -> forall a. e' -> ErrorT e m a
liftThrow forall a. e' -> m a
throwM e'
e = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ e' -> m (e ∨ a)
forall a. e' -> m a
throwM e'
e
liftCatch ∷ ∀ e' m. (Monad m) ⇒ (∀ a. m a → (e' → m a) → m a) → (∀ a. ErrorT e m a → (e' → ErrorT e m a) → ErrorT e m a)
liftCatch :: forall e' (m :: * -> *).
Monad m =>
(forall a. m a -> (e' -> m a) -> m a)
-> forall a. ErrorT e m a -> (e' -> ErrorT e m a) -> ErrorT e m a
liftCatch forall a. m a -> (e' -> m a) -> m a
catchM ErrorT e m a
xM e' -> ErrorT e m a
k = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a) -> (e' -> m (e ∨ a)) -> m (e ∨ a)
forall a. m a -> (e' -> m a) -> m a
catchM (ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM) ((e' -> m (e ∨ a)) -> m (e ∨ a)) -> (e' -> m (e ∨ a)) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ \ e'
e → ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m a -> m (e ∨ a)) -> ErrorT e m a -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ e' -> ErrorT e m a
k e'
e
instance LiftDelay (ErrorT e) where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ErrorT e m a) -> ErrorT e m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> ErrorT e m a
xMU = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ (() -> m (e ∨ a)) -> m (e ∨ a)
forall a. (() -> m a) -> m a
delayM ((() -> m (e ∨ a)) -> m (e ∨ a)) -> (() -> m (e ∨ a)) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ \ () → ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m a -> m (e ∨ a)) -> ErrorT e m a -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ () -> ErrorT e m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (ErrorT e m) where
delay :: forall a. (() -> ErrorT e m a) -> ErrorT e m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> ErrorT e m a) -> ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ErrorT e m a) -> ErrorT e m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet (ErrorT e) where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ErrorT e m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftMzero forall a. m a
mzeroM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a)
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. ErrorT e m a → ErrorT e m a → ErrorT e m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
liftMplus forall a. m a -> m a -> m a
mplusM ErrorT e m a
xM₁ ErrorT e m a
xM₂ = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a) -> m (e ∨ a) -> m (e ∨ a)
forall a. m a -> m a -> m a
mplusM (ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₁) (ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM₂)
instance (Monad m,MonadNondet m) ⇒ MonadNondet (ErrorT e m) where
mzero :: forall a. ErrorT e m a
mzero = (forall a. m a) -> forall a. ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. ErrorT e m a -> ErrorT e m a -> ErrorT e m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop (ErrorT e) where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. ErrorT e m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftMtop forall a. m a
mtopM = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$ m (e ∨ a)
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (ErrorT e m) where
mtop :: forall a. ErrorT e m a
mtop = (forall a. m a) -> forall a. ErrorT e m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. ErrorT e m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (Monad m,MonadCont (e ∨ r) m) ⇒ MonadCont r (ErrorT e m) where
callCC ∷ ∀ a. ((a → ErrorT e m r) → ErrorT e m r) → ErrorT e m a
callCC :: forall a. ((a -> ErrorT e m r) -> ErrorT e m r) -> ErrorT e m a
callCC (a -> ErrorT e m r) -> ErrorT e m r
kk = m (e ∨ a) -> ErrorT e m a
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ a) -> ErrorT e m a) -> m (e ∨ a) -> ErrorT e m a
forall a b. (a -> b) -> a -> b
$
(((e ∨ a) -> m (e ∨ r)) -> m (e ∨ r)) -> m (e ∨ a)
forall a. ((a -> m (e ∨ r)) -> m (e ∨ r)) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC ((((e ∨ a) -> m (e ∨ r)) -> m (e ∨ r)) -> m (e ∨ a))
-> (((e ∨ a) -> m (e ∨ r)) -> m (e ∨ r)) -> m (e ∨ a)
forall a b. (a -> b) -> a -> b
$ \ ((e ∨ a) -> m (e ∨ r)
k ∷ e ∨ a → m (e ∨ r)) →
ErrorT e m r -> m (e ∨ r)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m r -> m (e ∨ r)) -> ErrorT e m r -> m (e ∨ r)
forall a b. (a -> b) -> a -> b
$ (a -> ErrorT e m r) -> ErrorT e m r
kk ((a -> ErrorT e m r) -> ErrorT e m r)
-> (a -> ErrorT e m r) -> ErrorT e m r
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
m (e ∨ r) -> ErrorT e m r
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ r) -> ErrorT e m r) -> m (e ∨ r) -> ErrorT e m r
forall a b. (a -> b) -> a -> b
$ (e ∨ a) -> m (e ∨ r)
k (a -> e ∨ a
forall a b. b -> a ∨ b
Inr a
x)
withC ∷ ∀ a. (a → ErrorT e m r) → ErrorT e m a → ErrorT e m r
withC :: forall a. (a -> ErrorT e m r) -> ErrorT e m a -> ErrorT e m r
withC a -> ErrorT e m r
k ErrorT e m a
xM = m (e ∨ r) -> ErrorT e m r
forall e (m :: * -> *) a. m (e ∨ a) -> ErrorT e m a
ErrorT (m (e ∨ r) -> ErrorT e m r) -> m (e ∨ r) -> ErrorT e m r
forall a b. (a -> b) -> a -> b
$
((e ∨ a) -> m (e ∨ r)) -> m (e ∨ a) -> m (e ∨ r)
forall a. (a -> m (e ∨ r)) -> m a -> m (e ∨ r)
forall r (m :: * -> *) a. MonadCont r m => (a -> m r) -> m a -> m r
withC
(\ (e ∨ a
ex ∷ e ∨ a) → case e ∨ a
ex of
Inl e
e → (e ∨ r) -> m (e ∨ r)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((e ∨ r) -> m (e ∨ r)) -> (e ∨ r) -> m (e ∨ r)
forall a b. (a -> b) -> a -> b
$ e -> e ∨ r
forall a b. a -> a ∨ b
Inl e
e
Inr a
x → ErrorT e m r -> m (e ∨ r)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT (ErrorT e m r -> m (e ∨ r)) -> ErrorT e m r -> m (e ∨ r)
forall a b. (a -> b) -> a -> b
$ a -> ErrorT e m r
k a
x)
(ErrorT e m a -> m (e ∨ a)
forall e (m :: * -> *) a. ErrorT e m a -> m (e ∨ a)
unErrorT ErrorT e m a
xM)
instance LiftIO DelayT where
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> DelayT m a
liftIO forall a. IO a -> m a
ioM IO a
xM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
instance (Monad m,MonadIO m) ⇒ MonadIO (DelayT m) where
io :: forall a. IO a -> DelayT m a
io = (forall a. IO a -> m a) -> forall a. IO a -> DelayT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> DelayT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader DelayT where
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> DelayT m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = (() -> m r') -> DelayT m r'
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m r') -> DelayT m r') -> (() -> m r') -> DelayT m r'
forall a b. (a -> b) -> a -> b
$ \ () → (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> DelayT m a -> DelayT m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r DelayT m a
xM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM
instance (Monad m,MonadReader r m) ⇒ MonadReader r (DelayT m) where
askL :: forall r'. (r ⟢ r') -> DelayT m r'
askL = (forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> DelayT m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> DelayT m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> DelayT m a -> DelayT m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> DelayT m a -> DelayT m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> DelayT m a -> DelayT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance LiftWriter DelayT where
liftTell :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> DelayT m ()
liftTell o -> m ()
tellM o
o = (() -> m ()) -> DelayT m ()
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m ()) -> DelayT m ()) -> (() -> m ()) -> DelayT m ()
forall a b. (a -> b) -> a -> b
$ \ () → o -> m ()
tellM o
o
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. DelayT m a -> DelayT m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM DelayT m a
xM = (() -> m (o ∧ a)) -> DelayT m (o ∧ a)
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m (o ∧ a)) -> DelayT m (o ∧ a))
-> (() -> m (o ∧ a)) -> DelayT m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ () → m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
hijackM (m a -> m (o ∧ a)) -> m a -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (DelayT m) where
tell :: o -> DelayT m ()
tell = (o -> m ()) -> o -> DelayT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> DelayT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. DelayT m a -> DelayT m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. DelayT m a -> DelayT m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. DelayT m a -> DelayT m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState DelayT where
liftGet :: forall (m :: * -> *) a. Monad m => m a -> DelayT m a
liftGet m s
getM = (() -> m s) -> DelayT m s
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m s) -> DelayT m s) -> (() -> m s) -> DelayT m s
forall a b. (a -> b) -> a -> b
$ \ () → m s
getM
liftPut :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> DelayT m ()
liftPut s -> m ()
putM s
s = (() -> m ()) -> DelayT m ()
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m ()) -> DelayT m ()) -> (() -> m ()) -> DelayT m ()
forall a b. (a -> b) -> a -> b
$ \ () → s -> m ()
putM s
s
instance (Monad m,MonadState s m) ⇒ MonadState s (DelayT m) where
get :: DelayT m s
get = m s -> DelayT m s
forall (m :: * -> *) a. Monad m => m a -> DelayT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> DelayT m ()
put = (s -> m ()) -> s -> DelayT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> DelayT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail DelayT where
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftAbort forall a. m a
abortM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a
forall a. m a
abortM
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
liftTry forall a. m a -> m a -> m a
tryM DelayT m a
xM₁ DelayT m a
xM₂ = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a -> m a -> m a
forall a. m a -> m a -> m a
tryM (DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM₁) (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM₂
instance (Monad m,MonadFail m) ⇒ MonadFail (DelayT m) where
abort :: forall a. DelayT m a
abort = (forall a. m a) -> forall a. DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. DelayT m a -> DelayT m a -> DelayT m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError DelayT where
liftThrow :: forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> DelayT m a
liftThrow forall a. e -> m a
throwM e
e = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → e -> m a
forall a. e -> m a
throwM e
e
liftCatch :: forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. DelayT m a -> (e -> DelayT m a) -> DelayT m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM DelayT m a
xM e -> DelayT m a
f = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
catchM (DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM) ((e -> m a) -> m a) -> (e -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m a -> m a) -> (e -> DelayT m a) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ e -> DelayT m a
f
instance (Monad m,MonadError e m) ⇒ MonadError e (DelayT m) where
throw :: forall a. e -> DelayT m a
throw = (forall a. e -> m a) -> forall a. e -> DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> DelayT m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. DelayT m a -> (e -> DelayT m a) -> DelayT m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. DelayT m a -> (e -> DelayT m a) -> DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. DelayT m a -> (e -> DelayT m a) -> DelayT m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay DelayT where
liftDelay ∷ ∀ m. (Monad m) ⇒ (∀ a. (() → m a) → m a) → (∀ a. (() → DelayT m a) → DelayT m a)
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> DelayT m a) -> DelayT m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> DelayT m a
xMU = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → (() -> m a) -> m a
forall a. (() -> m a) -> m a
delayM ((() -> m a) -> m a) -> (() -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ \ () → DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m a -> m a) -> DelayT m a -> m a
forall a b. (a -> b) -> a -> b
$ () -> DelayT m a
xMU ()
instance LiftNondet DelayT where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. DelayT m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftMzero forall a. m a
mzeroM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ m a -> () -> m a
forall a b. a -> b -> a
const m a
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. DelayT m a → DelayT m a → DelayT m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
liftMplus forall a. m a -> m a -> m a
mplusM DelayT m a
xM DelayT m a
yM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () → m a -> m a -> m a
forall a. m a -> m a -> m a
mplusM (DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM) (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
yM
instance (Monad m,MonadNondet m) ⇒ MonadNondet (DelayT m) where
mzero :: forall a. DelayT m a
mzero = (forall a. m a) -> forall a. DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftMzero m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
⊞ :: forall a. DelayT m a -> DelayT m a -> DelayT m a
(⊞) = (forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftNondet t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. DelayT m a -> DelayT m a -> DelayT m a
liftMplus m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞)
instance LiftTop DelayT where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. DelayT m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftMtop forall a. m a
mtopM = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ m a -> () -> m a
forall a b. a -> b -> a
const m a
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (DelayT m) where
mtop :: forall a. DelayT m a
mtop = (forall a. m a) -> forall a. DelayT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. DelayT m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (MonadCont r m) ⇒ MonadCont r (DelayT m) where
callCC :: forall a. ((a -> DelayT m r) -> DelayT m r) -> DelayT m a
callCC (a -> DelayT m r) -> DelayT m r
𝓀𝓀 = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () →
((a -> m r) -> m r) -> m a
forall a. ((a -> m r) -> m r) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC (((a -> m r) -> m r) -> m a) -> ((a -> m r) -> m r) -> m a
forall a b. (a -> b) -> a -> b
$ \ a -> m r
𝓀 → DelayT m r -> m r
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m r -> m r) -> DelayT m r -> m r
forall a b. (a -> b) -> a -> b
$ (a -> DelayT m r) -> DelayT m r
𝓀𝓀 ((a -> DelayT m r) -> DelayT m r)
-> (a -> DelayT m r) -> DelayT m r
forall a b. (a -> b) -> a -> b
$ \ a
x → (() -> m r) -> DelayT m r
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m r) -> DelayT m r) -> (() -> m r) -> DelayT m r
forall a b. (a -> b) -> a -> b
$ \ () → a -> m r
𝓀 a
x
withC :: forall a. (a -> DelayT m r) -> DelayT m a -> DelayT m r
withC a -> DelayT m r
𝓀 DelayT m a
xM = (() -> m r) -> DelayT m r
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m r) -> DelayT m r) -> (() -> m r) -> DelayT m r
forall a b. (a -> b) -> a -> b
$ \ () → (a -> m r) -> m a -> m r
forall a. (a -> m r) -> m a -> m r
forall r (m :: * -> *) a. MonadCont r m => (a -> m r) -> m a -> m r
withC (DelayT m r -> m r
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m r -> m r) -> (a -> DelayT m r) -> a -> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ a -> DelayT m r
𝓀) (m a -> m r) -> m a -> m r
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM
instance (MonadUCont m) ⇒ MonadUCont (DelayT m) where
ucallCC :: forall a. (forall u. (a -> DelayT m u) -> DelayT m u) -> DelayT m a
ucallCC forall u. (a -> DelayT m u) -> DelayT m u
𝓀𝓀 = (() -> m a) -> DelayT m a
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m a) -> DelayT m a) -> (() -> m a) -> DelayT m a
forall a b. (a -> b) -> a -> b
$ \ () →
(forall u. (a -> m u) -> m u) -> m a
forall a. (forall u. (a -> m u) -> m u) -> m a
forall (m :: * -> *) a.
MonadUCont m =>
(forall u. (a -> m u) -> m u) -> m a
ucallCC (\ a -> m u
𝓀 → DelayT m u -> m u
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m u -> m u) -> DelayT m u -> m u
forall a b. (a -> b) -> a -> b
$ (a -> DelayT m u) -> DelayT m u
forall u. (a -> DelayT m u) -> DelayT m u
𝓀𝓀 ((a -> DelayT m u) -> DelayT m u)
-> (a -> DelayT m u) -> DelayT m u
forall a b. (a -> b) -> a -> b
$ \ a
x → (() -> m u) -> DelayT m u
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m u) -> DelayT m u) -> (() -> m u) -> DelayT m u
forall a b. (a -> b) -> a -> b
$ \ () → a -> m u
𝓀 a
x)
uwithC :: forall a u. (a -> DelayT m u) -> DelayT m a -> DelayT m u
uwithC a -> DelayT m u
𝓀 DelayT m a
xM = (() -> m u) -> DelayT m u
forall {k} (m :: k -> *) (a :: k). (() -> m a) -> DelayT m a
DelayT ((() -> m u) -> DelayT m u) -> (() -> m u) -> DelayT m u
forall a b. (a -> b) -> a -> b
$ \ () → (a -> m u) -> m a -> m u
forall a u. (a -> m u) -> m a -> m u
forall (m :: * -> *) a u. MonadUCont m => (a -> m u) -> m a -> m u
uwithC (DelayT m u -> m u
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT (DelayT m u -> m u) -> (a -> DelayT m u) -> a -> m u
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ a -> DelayT m u
𝓀) (m a -> m u) -> m a -> m u
forall a b. (a -> b) -> a -> b
$ DelayT m a -> m a
forall {k} (m :: k -> *) (a :: k). DelayT m a -> m a
runDelayT DelayT m a
xM
instance LiftIO NondetT where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → NondetT m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> NondetT m a
liftIO forall a. IO a -> m a
ioM IO a
xM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
𝑄 a -> m (𝑄 a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 a -> m (𝑄 a)) -> 𝑄 a -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ a -> 𝑄 a
forall a t. Single a t => a -> t
single a
x
instance (Monad m,MonadIO m) ⇒ MonadIO (NondetT m) where
io :: forall a. IO a -> NondetT m a
io = (forall a. IO a -> m a) -> forall a. IO a -> NondetT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> NondetT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance LiftReader NondetT where
liftAskL ∷ ∀ m r. (Monad m) ⇒ (∀ r'. r ⟢ r' → m r') → (∀ r'. r ⟢ r' → NondetT m r')
liftAskL :: forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> NondetT m r'
liftAskL forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ = m (𝑄 r') -> NondetT m r'
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 r') -> NondetT m r') -> m (𝑄 r') -> NondetT m r'
forall a b. (a -> b) -> a -> b
$ do
r'
r ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
askLM r ⟢ r'
ℓ
𝑄 r' -> m (𝑄 r')
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 r' -> m (𝑄 r')) -> 𝑄 r' -> m (𝑄 r')
forall a b. (a -> b) -> a -> b
$ r' -> 𝑄 r'
forall a t. Single a t => a -> t
single r'
r
liftLocalL ∷ ∀ m r. (Monad m) ⇒ (∀ r' a. r ⟢ r' → r' → m a → m a) → (∀ r' a. r ⟢ r' → r' → NondetT m a → NondetT m a)
liftLocalL :: forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> NondetT m a -> NondetT m a
liftLocalL forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r NondetT m a
xM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ (r ⟢ r') -> r' -> m (𝑄 a) -> m (𝑄 a)
forall r' a. (r ⟢ r') -> r' -> m a -> m a
localLM r ⟢ r'
ℓ r'
r (m (𝑄 a) -> m (𝑄 a)) -> m (𝑄 a) -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM
instance (Monad m,MonadReader r m) ⇒ MonadReader r (NondetT m) where
askL :: forall r'. (r ⟢ r') -> NondetT m r'
askL = (forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> NondetT m r'
forall (m :: * -> *) r.
Monad m =>
(forall r'. (r ⟢ r') -> m r')
-> forall r'. (r ⟢ r') -> NondetT m r'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r'. (r ⟢ r') -> m r') -> forall r'. (r ⟢ r') -> t m r'
liftAskL (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL
localL :: forall a r'. (r ⟢ r') -> r' -> NondetT m a -> NondetT m a
localL = (forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> NondetT m a -> NondetT m a
forall (m :: * -> *) r.
Monad m =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> NondetT m a -> NondetT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(LiftReader t, Monad m) =>
(forall r' a. (r ⟢ r') -> r' -> m a -> m a)
-> forall r' a. (r ⟢ r') -> r' -> t m a -> t m a
liftLocalL (r ⟢ r') -> r' -> m a -> m a
forall r' a. (r ⟢ r') -> r' -> m a -> m a
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL
instance LiftWriter NondetT where
liftTell ∷ ∀ m o. (Monad m) ⇒ (o → m ()) → (o → NondetT m ())
liftTell :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> NondetT m ()
liftTell o -> m ()
tellM o
o = m (𝑄 ()) -> NondetT m ()
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 ()) -> NondetT m ()) -> m (𝑄 ()) -> NondetT m ()
forall a b. (a -> b) -> a -> b
$ do
o -> m ()
tellM o
o
𝑄 () -> m (𝑄 ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 () -> m (𝑄 ())) -> 𝑄 () -> m (𝑄 ())
forall a b. (a -> b) -> a -> b
$ () -> 𝑄 ()
forall a t. Single a t => a -> t
single ()
liftHijack ∷ ∀ m o. (Monad m) ⇒ (∀ a. m a → m (o ∧ a)) → (∀ a. NondetT m a → NondetT m (o ∧ a))
liftHijack :: forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. NondetT m a -> NondetT m (o ∧ a)
liftHijack forall a. m a -> m (o ∧ a)
hijackM NondetT m a
xM = m (𝑄 (o ∧ a)) -> NondetT m (o ∧ a)
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 (o ∧ a)) -> NondetT m (o ∧ a))
-> m (𝑄 (o ∧ a)) -> NondetT m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ do
(o
o :* 𝑄 a
xs) ← m (𝑄 a) -> m (o ∧ 𝑄 a)
forall a. m a -> m (o ∧ a)
hijackM (m (𝑄 a) -> m (o ∧ 𝑄 a)) -> m (𝑄 a) -> m (o ∧ 𝑄 a)
forall a b. (a -> b) -> a -> b
$ NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM
𝑄 (o ∧ a) -> m (𝑄 (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 (o ∧ a) -> m (𝑄 (o ∧ a))) -> 𝑄 (o ∧ a) -> m (𝑄 (o ∧ a))
forall a b. (a -> b) -> a -> b
$ (a -> o ∧ a) -> 𝑄 a -> 𝑄 (o ∧ a)
forall a b. (a -> b) -> 𝑄 a -> 𝑄 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map (o
o o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* ) 𝑄 a
xs
instance (Monad m,MonadWriter o m) ⇒ MonadWriter o (NondetT m) where
tell :: o -> NondetT m ()
tell = (o -> m ()) -> o -> NondetT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> NondetT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(o -> m ()) -> o -> t m ()
liftTell o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell
hijack :: forall a. NondetT m a -> NondetT m (o ∧ a)
hijack = (forall a. m a -> m (o ∧ a))
-> forall a. NondetT m a -> NondetT m (o ∧ a)
forall (m :: * -> *) o.
Monad m =>
(forall a. m a -> m (o ∧ a))
-> forall a. NondetT m a -> NondetT m (o ∧ a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) o.
(LiftWriter t, Monad m) =>
(forall a. m a -> m (o ∧ a)) -> forall a. t m a -> t m (o ∧ a)
liftHijack m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack
instance LiftState NondetT where
liftGet ∷ ∀ m s. (Monad m) ⇒ m s → NondetT m s
liftGet :: forall (m :: * -> *) a. Monad m => m a -> NondetT m a
liftGet m s
getM = m (𝑄 s) -> NondetT m s
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 s) -> NondetT m s) -> m (𝑄 s) -> NondetT m s
forall a b. (a -> b) -> a -> b
$ do
s
s ← m s
getM
𝑄 s -> m (𝑄 s)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 s -> m (𝑄 s)) -> 𝑄 s -> m (𝑄 s)
forall a b. (a -> b) -> a -> b
$ s -> 𝑄 s
forall a t. Single a t => a -> t
single s
s
liftPut ∷ ∀ m s. (Monad m) ⇒ (s → m ()) → s → NondetT m ()
liftPut :: forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> NondetT m ()
liftPut s -> m ()
putM s
s = m (𝑄 ()) -> NondetT m ()
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 ()) -> NondetT m ()) -> m (𝑄 ()) -> NondetT m ()
forall a b. (a -> b) -> a -> b
$ do
s -> m ()
putM s
s
𝑄 () -> m (𝑄 ())
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (𝑄 () -> m (𝑄 ())) -> 𝑄 () -> m (𝑄 ())
forall a b. (a -> b) -> a -> b
$ () -> 𝑄 ()
forall a t. Single a t => a -> t
single ()
instance (Monad m,MonadState s m) ⇒ MonadState s (NondetT m) where
get :: NondetT m s
get = m s -> NondetT m s
forall (m :: * -> *) a. Monad m => m a -> NondetT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
m s -> t m s
liftGet m s
forall s (m :: * -> *). MonadState s m => m s
get
put :: s -> NondetT m ()
put = (s -> m ()) -> s -> NondetT m ()
forall (m :: * -> *) o. Monad m => (o -> m ()) -> o -> NondetT m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) s.
(LiftState t, Monad m) =>
(s -> m ()) -> s -> t m ()
liftPut s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
instance LiftFail NondetT where
liftAbort ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. NondetT m a)
liftAbort :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. NondetT m a
liftAbort forall a. m a
abortM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a)
forall a. m a
abortM
liftTry ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. NondetT m a → NondetT m a → NondetT m a)
liftTry :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. NondetT m a -> NondetT m a -> NondetT m a
liftTry forall a. m a -> m a -> m a
tryM NondetT m a
xM₁ NondetT m a
xM₂ = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a) -> m (𝑄 a) -> m (𝑄 a)
forall a. m a -> m a -> m a
tryM (NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₁) (NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₂)
instance (Monad m,MonadFail m) ⇒ MonadFail (NondetT m) where
abort :: forall a. NondetT m a
abort = (forall a. m a) -> forall a. NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. NondetT m a
liftAbort m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
⎅ :: forall a. NondetT m a -> NondetT m a -> NondetT m a
(⎅) = (forall a. m a -> m a -> m a)
-> forall a. NondetT m a -> NondetT m a -> NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftFail t, Monad m) =>
(forall a. m a -> m a -> m a)
-> forall (a :: k). t m a -> t m a -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. NondetT m a -> NondetT m a -> NondetT m a
liftTry m a -> m a -> m a
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
(⎅)
instance LiftError NondetT where
liftThrow ∷ ∀ m e. (Monad m) ⇒ (∀ a. e → m a) → (∀ a. e → NondetT m a)
liftThrow :: forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> NondetT m a
liftThrow forall a. e -> m a
throwM e
e = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ e -> m (𝑄 a)
forall a. e -> m a
throwM e
e
liftCatch ∷ ∀ m e. (Monad m) ⇒ (∀ a. m a → (e → m a) → m a) → (∀ a. NondetT m a → (e → NondetT m a) → NondetT m a)
liftCatch :: forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. NondetT m a -> (e -> NondetT m a) -> NondetT m a
liftCatch forall a. m a -> (e -> m a) -> m a
catchM NondetT m a
xM e -> NondetT m a
k = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a) -> (e -> m (𝑄 a)) -> m (𝑄 a)
forall a. m a -> (e -> m a) -> m a
catchM (NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM) ((e -> m (𝑄 a)) -> m (𝑄 a)) -> (e -> m (𝑄 a)) -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ \ e
e → NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT (NondetT m a -> m (𝑄 a)) -> NondetT m a -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ e -> NondetT m a
k e
e
instance (Monad m,MonadError e m) ⇒ MonadError e (NondetT m) where
throw :: forall a. e -> NondetT m a
throw = (forall a. e -> m a) -> forall a. e -> NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. e -> m a) -> forall (a :: k). e -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. e -> m a) -> forall a. e -> NondetT m a
liftThrow e -> m a
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw
catch :: forall a. NondetT m a -> (e -> NondetT m a) -> NondetT m a
catch = (forall a. m a -> (e -> m a) -> m a)
-> forall a. NondetT m a -> (e -> NondetT m a) -> NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) e.
(LiftError t, Monad m) =>
(forall a. m a -> (e -> m a) -> m a)
-> forall (a :: k). t m a -> (e -> t m a) -> t m a
forall (m :: * -> *) e.
Monad m =>
(forall a. m a -> (e -> m a) -> m a)
-> forall a. NondetT m a -> (e -> NondetT m a) -> NondetT m a
liftCatch m a -> (e -> m a) -> m a
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch
instance LiftDelay NondetT where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> NondetT m a) -> NondetT m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> NondetT m a
xMU = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ (() -> m (𝑄 a)) -> m (𝑄 a)
forall a. (() -> m a) -> m a
delayM ((() -> m (𝑄 a)) -> m (𝑄 a)) -> (() -> m (𝑄 a)) -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ \ () → NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT (NondetT m a -> m (𝑄 a)) -> NondetT m a -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ () -> NondetT m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (NondetT m) where
delay :: forall a. (() -> NondetT m a) -> NondetT m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> NondetT m a) -> NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> NondetT m a) -> NondetT m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance LiftNondet NondetT where
liftMzero ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. NondetT m a)
liftMzero :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. NondetT m a
liftMzero forall a. m a
mzeroM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a)
forall a. m a
mzeroM
liftMplus ∷ ∀ m. (Monad m) ⇒ (∀ a. m a → m a → m a) → (∀ a. NondetT m a → NondetT m a → NondetT m a)
liftMplus :: forall (m :: * -> *).
Monad m =>
(forall a. m a -> m a -> m a)
-> forall a. NondetT m a -> NondetT m a -> NondetT m a
liftMplus forall a. m a -> m a -> m a
mplusM NondetT m a
xM₁ NondetT m a
xM₂ = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a) -> m (𝑄 a) -> m (𝑄 a)
forall a. m a -> m a -> m a
mplusM (NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₁) (NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM₂)
instance LiftTop NondetT where
liftMtop ∷ ∀ m. (Monad m) ⇒ (∀ a. m a) → (∀ a. NondetT m a)
liftMtop :: forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. NondetT m a
liftMtop forall a. m a
mtopM = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$ m (𝑄 a)
forall a. m a
mtopM
instance (Monad m,MonadTop m) ⇒ MonadTop (NondetT m) where
mtop :: forall a. NondetT m a
mtop = (forall a. m a) -> forall a. NondetT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftTop t, Monad m) =>
(forall a. m a) -> forall (a :: k). t m a
forall (m :: * -> *).
Monad m =>
(forall a. m a) -> forall a. NondetT m a
liftMtop m a
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance (Monad m,Func Monoid m,MonadCont (𝑄 r) m) ⇒ MonadCont r (NondetT m) where
callCC ∷ ∀ a. ((a → NondetT m r) → NondetT m r) → NondetT m a
callCC :: forall a. ((a -> NondetT m r) -> NondetT m r) -> NondetT m a
callCC (a -> NondetT m r) -> NondetT m r
kk = m (𝑄 a) -> NondetT m a
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 a) -> NondetT m a) -> m (𝑄 a) -> NondetT m a
forall a b. (a -> b) -> a -> b
$
((𝑄 a -> m (𝑄 r)) -> m (𝑄 r)) -> m (𝑄 a)
forall a. ((a -> m (𝑄 r)) -> m (𝑄 r)) -> m a
forall r (m :: * -> *) a.
MonadCont r m =>
((a -> m r) -> m r) -> m a
callCC (((𝑄 a -> m (𝑄 r)) -> m (𝑄 r)) -> m (𝑄 a))
-> ((𝑄 a -> m (𝑄 r)) -> m (𝑄 r)) -> m (𝑄 a)
forall a b. (a -> b) -> a -> b
$ \ (𝑄 a -> m (𝑄 r)
k ∷ 𝑄 a → m (𝑄 r)) →
NondetT m r -> m (𝑄 r)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT (NondetT m r -> m (𝑄 r)) -> NondetT m r -> m (𝑄 r)
forall a b. (a -> b) -> a -> b
$ (a -> NondetT m r) -> NondetT m r
kk ((a -> NondetT m r) -> NondetT m r)
-> (a -> NondetT m r) -> NondetT m r
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) →
m (𝑄 r) -> NondetT m r
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 r) -> NondetT m r) -> m (𝑄 r) -> NondetT m r
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> m (𝑄 r)
k (a -> 𝑄 a
forall a t. Single a t => a -> t
single a
x)
withC ∷ ∀ a. (a → NondetT m r) → NondetT m a → NondetT m r
withC :: forall a. (a -> NondetT m r) -> NondetT m a -> NondetT m r
withC a -> NondetT m r
k NondetT m a
xM = m (𝑄 r) -> NondetT m r
forall (m :: * -> *) a. m (𝑄 a) -> NondetT m a
NondetT (m (𝑄 r) -> NondetT m r) -> m (𝑄 r) -> NondetT m r
forall a b. (a -> b) -> a -> b
$
(𝑄 a -> m (𝑄 r)) -> m (𝑄 a) -> m (𝑄 r)
forall a. (a -> m (𝑄 r)) -> m a -> m (𝑄 r)
forall r (m :: * -> *) a. MonadCont r m => (a -> m r) -> m a -> m r
withC
(\ (𝑄 a
xs ∷ 𝑄 a) → NondetT m r -> m (𝑄 r)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT (NondetT m r -> m (𝑄 r)) -> NondetT m r -> m (𝑄 r)
forall a b. (a -> b) -> a -> b
$ NondetT m r
-> (NondetT m r -> NondetT m r -> NondetT m r)
-> 𝐼 (NondetT m r)
-> NondetT m r
forall a t b. ToIter a t => b -> (a -> b -> b) -> t -> b
foldr NondetT m r
forall a. NondetT m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero NondetT m r -> NondetT m r -> NondetT m r
forall a. NondetT m a -> NondetT m a -> NondetT m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
(⊞) (𝐼 (NondetT m r) -> NondetT m r) -> 𝐼 (NondetT m r) -> NondetT m r
forall a b. (a -> b) -> a -> b
$ (a -> NondetT m r) -> 𝐼 a -> 𝐼 (NondetT m r)
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map a -> NondetT m r
k (𝐼 a -> 𝐼 (NondetT m r)) -> 𝐼 a -> 𝐼 (NondetT m r)
forall a b. (a -> b) -> a -> b
$ 𝑄 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter 𝑄 a
xs)
(NondetT m a -> m (𝑄 a)
forall (m :: * -> *) a. NondetT m a -> m (𝑄 a)
unNondetT NondetT m a
xM)
instance LiftIO (ContT u) where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → ContT u m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ContT u m a
liftIO forall a. IO a -> m a
ioM IO a
xM = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → do
a
x ← IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
a -> m u
k a
x
instance (Monad m,MonadIO m) ⇒ MonadIO (ContT u m) where
io :: forall a. IO a -> ContT u m a
io = (forall a. IO a -> m a) -> forall a. IO a -> ContT u m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> ContT u m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance (Monad m,MonadReader r m) ⇒ MonadReader r (ContT u m) where
askL ∷ ∀ r'. r ⟢ r' → ContT u m r'
askL :: forall r'. (r ⟢ r') -> ContT u m r'
askL r ⟢ r'
ℓ = ((r' -> m u) -> m u) -> ContT u m r'
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((r' -> m u) -> m u) -> ContT u m r')
-> ((r' -> m u) -> m u) -> ContT u m r'
forall a b. (a -> b) -> a -> b
$ \ (r' -> m u
k ∷ r' → m u) → r' -> m u
k (r' -> m u) -> m r' -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL r ⟢ r'
ℓ
localL ∷ ∀ r' a. r ⟢ r' → r' → ContT u m a → ContT u m a
localL :: forall r' a. (r ⟢ r') -> r' -> ContT u m a -> ContT u m a
localL r ⟢ r'
ℓ r'
r ContT u m a
xM = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m u) → do
r'
r' ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL r ⟢ r'
ℓ
(r ⟢ r') -> r' -> m u -> m u
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL r ⟢ r'
ℓ r'
r (m u -> m u) -> m u -> m u
forall a b. (a -> b) -> a -> b
$ ContT u m a -> (a -> m u) -> m u
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT u m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ a
x → do
(r ⟢ r') -> r' -> m u -> m u
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL r ⟢ r'
ℓ r'
r' (m u -> m u) -> m u -> m u
forall a b. (a -> b) -> a -> b
$ a -> m u
k a
x
instance (Monad m,Monoid o,MonadWriter o m) ⇒ MonadWriter o (ContT (o ∧ r) m) where
tell ∷ o → ContT (o ∧ r) m ()
tell :: o -> ContT (o ∧ r) m ()
tell o
o = ((() -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m ()
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((() -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m ())
-> ((() -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m ()
forall a b. (a -> b) -> a -> b
$ \ (() -> m (o ∧ r)
k ∷ () → m (o ∧ r)) → do
o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell o
o
() -> m (o ∧ r)
k ()
hijack ∷ ∀ a. ContT (o ∧ r) m a → ContT (o ∧ r) m (o ∧ a)
hijack :: forall a. ContT (o ∧ r) m a -> ContT (o ∧ r) m (o ∧ a)
hijack ContT (o ∧ r) m a
xM = (((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m (o ∧ a)
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT ((((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m (o ∧ a))
-> (((o ∧ a) -> m (o ∧ r)) -> m (o ∧ r)) -> ContT (o ∧ r) m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ ((o ∧ a) -> m (o ∧ r)
k ∷ (o ∧ a) → m (o ∧ r)) → do
o
o :* o ∧ r
ox ← m (o ∧ r) -> m (o ∧ (o ∧ r))
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack (m (o ∧ r) -> m (o ∧ (o ∧ r))) -> m (o ∧ r) -> m (o ∧ (o ∧ r))
forall a b. (a -> b) -> a -> b
$ ContT (o ∧ r) m a -> (a -> m (o ∧ r)) -> m (o ∧ r)
forall {k} (u :: k) (m :: k -> *) a.
ContT u m a -> (a -> m u) -> m u
unContT ContT (o ∧ r) m a
xM ((a -> m (o ∧ r)) -> m (o ∧ r)) -> (a -> m (o ∧ r)) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ \ (a
x ∷ a) → do
o
o₁ :* (o
o₂ :* r
r) ← m (o ∧ r) -> m (o ∧ (o ∧ r))
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack (m (o ∧ r) -> m (o ∧ (o ∧ r))) -> m (o ∧ r) -> m (o ∧ (o ∧ r))
forall a b. (a -> b) -> a -> b
$ (o ∧ a) -> m (o ∧ r)
k ((o ∧ a) -> m (o ∧ r)) -> (o ∧ a) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ o
forall a. Null a => a
null o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
x
(o ∧ r) -> m (o ∧ r)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return ((o ∧ r) -> m (o ∧ r)) -> (o ∧ r) -> m (o ∧ r)
forall a b. (a -> b) -> a -> b
$ (o
o₁ o -> o -> o
forall a. Append a => a -> a -> a
⧺ o
o₂) o -> r -> o ∧ r
forall a b. a -> b -> a ∧ b
:* r
r
o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell o
o
(o ∧ r) -> m (o ∧ r)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return o ∧ r
ox
instance (Monad m,MonadState s m) ⇒ MonadState s (ContT u m) where
get ∷ ContT u m s
get :: ContT u m s
get = ((s -> m u) -> m u) -> ContT u m s
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((s -> m u) -> m u) -> ContT u m s)
-> ((s -> m u) -> m u) -> ContT u m s
forall a b. (a -> b) -> a -> b
$ \ (s -> m u
k ∷ s → m r) → do
s
s ← m s
forall s (m :: * -> *). MonadState s m => m s
get
s -> m u
k s
s
put ∷ s → ContT u m ()
put :: s -> ContT u m ()
put s
s = ((() -> m u) -> m u) -> ContT u m ()
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((() -> m u) -> m u) -> ContT u m ())
-> ((() -> m u) -> m u) -> ContT u m ()
forall a b. (a -> b) -> a -> b
$ \ (() -> m u
k ∷ () → m r) → do
s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put s
s
() -> m u
k ()
instance (Monad m,MonadFail m) ⇒ MonadFail (ContT u m) where
abort ∷ ∀ a. ContT u m a
abort :: forall a. ContT u m a
abort = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
_ ∷ a → m r) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
(⎅) ∷ ∀ a. ContT u m a → ContT u m a → ContT u m a
ContT u m a
xM₁ ⎅ :: forall a. ContT u m a -> ContT u m a -> ContT u m a
⎅ ContT u m a
xM₂ = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → do
(a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k ContT u m a
xM₁ m u -> m u -> m u
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
⎅ (a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k ContT u m a
xM₂
instance (Monad m,MonadError e m) ⇒ MonadError e (ContT u m) where
throw ∷ ∀ a. e → ContT u m a
throw :: forall a. e -> ContT u m a
throw e
e = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
_ ∷ a → m r) → e -> m u
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw e
e
catch ∷ ∀ a. ContT u m a → (e → ContT u m a) → ContT u m a
catch :: forall a. ContT u m a -> (e -> ContT u m a) -> ContT u m a
catch ContT u m a
xM₁ e -> ContT u m a
kk = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → do
m u -> (e -> m u) -> m u
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch ((a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k ContT u m a
xM₁) ((e -> m u) -> m u) -> (e -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ e
e →
(a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k (ContT u m a -> m u) -> ContT u m a -> m u
forall a b. (a -> b) -> a -> b
$ e -> ContT u m a
kk e
e
instance LiftDelay (ContT u) where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ContT u m a) -> ContT u m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> ContT u m a
xMU = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ a -> m u
𝓀 → (() -> m u) -> m u
forall a. (() -> m a) -> m a
delayM ((() -> m u) -> m u) -> (() -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ () → (a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
𝓀 (ContT u m a -> m u) -> ContT u m a -> m u
forall a b. (a -> b) -> a -> b
$ () -> ContT u m a
xMU ()
instance (Monad m,MonadDelay m) ⇒ MonadDelay (ContT u m) where
delay :: forall a. (() -> ContT u m a) -> ContT u m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> ContT u m a) -> ContT u m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> ContT u m a) -> ContT u m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance (Monad m,MonadNondet m) ⇒ MonadNondet (ContT u m) where
mzero ∷ ∀ a. ContT u m a
mzero :: forall a. ContT u m a
mzero = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
_ ∷ a → m r) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
(⊞) ∷ ∀ a. ContT u m a → ContT u m a → ContT u m a
ContT u m a
xM₁ ⊞ :: forall a. ContT u m a -> ContT u m a -> ContT u m a
⊞ ContT u m a
xM₂ = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
k ∷ a → m r) → do
(a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k ContT u m a
xM₁ m u -> m u -> m u
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
⊞ (a -> m u) -> ContT u m a -> m u
forall {k} a (m :: k -> *) (u :: k).
(a -> m u) -> ContT u m a -> m u
runContT a -> m u
k ContT u m a
xM₂
instance (Monad m,MonadTop m) ⇒ MonadTop (ContT u m) where
mtop ∷ ∀ a. ContT u m a
mtop :: forall a. ContT u m a
mtop = ((a -> m u) -> m u) -> ContT u m a
forall {k} (u :: k) (m :: k -> *) a.
((a -> m u) -> m u) -> ContT u m a
ContT (((a -> m u) -> m u) -> ContT u m a)
-> ((a -> m u) -> m u) -> ContT u m a
forall a b. (a -> b) -> a -> b
$ \ (a -> m u
_ ∷ a → m r) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
instance LiftIO UContT where
liftIO ∷ ∀ m. (Monad m) ⇒ (∀ a. IO a → m a) → (∀ a. IO a → UContT m a)
liftIO :: forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> UContT m a
liftIO forall a. IO a -> m a
ioM IO a
xM = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
𝓀 ∷ a → m u) → a -> m u
𝓀 (a -> m u) -> m a -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ IO a -> m a
forall a. IO a -> m a
ioM IO a
xM
instance (Monad m,MonadIO m) ⇒ MonadIO (UContT m) where
io :: forall a. IO a -> UContT m a
io = (forall a. IO a -> m a) -> forall a. IO a -> UContT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> forall a. IO a -> UContT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(LiftIO t, Monad m) =>
(forall a. IO a -> m a) -> forall a. IO a -> t m a
liftIO IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
instance (Monad m,MonadReader r m) ⇒ MonadReader r (UContT m) where
askL ∷ ∀ r'. r ⟢ r' → UContT m r'
askL :: forall r'. (r ⟢ r') -> UContT m r'
askL r ⟢ r'
ℓ = (forall u. (r' -> m u) -> m u) -> UContT m r'
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (r' -> m u) -> m u) -> UContT m r')
-> (forall u. (r' -> m u) -> m u) -> UContT m r'
forall a b. (a -> b) -> a -> b
HS.$ \ (r' -> m u
𝓀 ∷ r' → m u) → r' -> m u
𝓀 (r' -> m u) -> m r' -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL r ⟢ r'
ℓ
localL ∷ ∀ r' a. r ⟢ r' → r' → UContT m a → UContT m a
localL :: forall r' a. (r ⟢ r') -> r' -> UContT m a -> UContT m a
localL r ⟢ r'
ℓ r'
r UContT m a
xM = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
𝓀 ∷ a → m u) → do
r'
r' ← (r ⟢ r') -> m r'
forall r'. (r ⟢ r') -> m r'
forall r (m :: * -> *) r'. MonadReader r m => (r ⟢ r') -> m r'
askL r ⟢ r'
ℓ
(r ⟢ r') -> r' -> m u -> m u
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL r ⟢ r'
ℓ r'
r (m u -> m u) -> m u -> m u
forall a b. (a -> b) -> a -> b
$ UContT m a -> forall u. (a -> m u) -> m u
forall {k} (m :: k -> *) a.
UContT m a -> forall (u :: k). (a -> m u) -> m u
unUContT UContT m a
xM ((a -> m u) -> m u) -> (a -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ a
x → do
(r ⟢ r') -> r' -> m u -> m u
forall a r'. (r ⟢ r') -> r' -> m a -> m a
forall r (m :: * -> *) a r'.
MonadReader r m =>
(r ⟢ r') -> r' -> m a -> m a
localL r ⟢ r'
ℓ r'
r' (m u -> m u) -> m u -> m u
forall a b. (a -> b) -> a -> b
$ a -> m u
𝓀 a
x
instance (Monad m,Monoid o,MonadWriter o m) ⇒ MonadWriter o (UContT m) where
tell ∷ o → UContT m ()
tell :: o -> UContT m ()
tell o
o = (forall u. (() -> m u) -> m u) -> UContT m ()
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (() -> m u) -> m u) -> UContT m ())
-> (forall u. (() -> m u) -> m u) -> UContT m ()
forall a b. (a -> b) -> a -> b
HS.$ \ (() -> m u
𝓀 ∷ () → m u) → () -> m u
𝓀 (() -> m u) -> m () -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ o -> m ()
forall o (m :: * -> *). MonadWriter o m => o -> m ()
tell o
o
hijack ∷ ∀ a. UContT m a → UContT m (o ∧ a)
hijack :: forall a. UContT m a -> UContT m (o ∧ a)
hijack UContT m a
xM = (forall u. ((o ∧ a) -> m u) -> m u) -> UContT m (o ∧ a)
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. ((o ∧ a) -> m u) -> m u) -> UContT m (o ∧ a))
-> (forall u. ((o ∧ a) -> m u) -> m u) -> UContT m (o ∧ a)
forall a b. (a -> b) -> a -> b
HS.$ \ ((o ∧ a) -> m u
𝓀 ∷ (o ∧ a) → m u) → (o ∧ a) -> m u
𝓀 ((o ∧ a) -> m u) -> m (o ∧ a) -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ m a -> m (o ∧ a)
forall a. m a -> m (o ∧ a)
forall o (m :: * -> *) a. MonadWriter o m => m a -> m (o ∧ a)
hijack (m a -> m (o ∧ a)) -> m a -> m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ UContT m a -> m a
forall (m :: * -> *) a. Return m => UContT m a -> m a
evalUContT UContT m a
xM
instance (Monad m,MonadState s m) ⇒ MonadState s (UContT m) where
get ∷ UContT m s
get :: UContT m s
get = (forall u. (s -> m u) -> m u) -> UContT m s
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (s -> m u) -> m u) -> UContT m s)
-> (forall u. (s -> m u) -> m u) -> UContT m s
forall a b. (a -> b) -> a -> b
HS.$ \ (s -> m u
𝓀 ∷ s → m u) → s -> m u
𝓀 (s -> m u) -> m s -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ m s
forall s (m :: * -> *). MonadState s m => m s
get
put ∷ s → UContT m ()
put :: s -> UContT m ()
put s
s = (forall u. (() -> m u) -> m u) -> UContT m ()
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (() -> m u) -> m u) -> UContT m ())
-> (forall u. (() -> m u) -> m u) -> UContT m ()
forall a b. (a -> b) -> a -> b
HS.$ \ (() -> m u
𝓀 ∷ () → m u) → () -> m u
𝓀 (() -> m u) -> m () -> m u
forall (m :: * -> *) a b. Bind m => (a -> m b) -> m a -> m b
*$ s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put s
s
instance (Monad m,MonadFail m) ⇒ MonadFail (UContT m) where
abort ∷ ∀ a. UContT m a
abort :: forall a. UContT m a
abort = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
_ ∷ a → m u) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a
abort
(⎅) ∷ ∀ a. UContT m a → UContT m a → UContT m a
UContT m a
xM₁ ⎅ :: forall a. UContT m a -> UContT m a -> UContT m a
⎅ UContT m a
xM₂ = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
k ∷ a → m u) → do
(a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM₁ m u -> m u -> m u
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k). MonadFail m => m a -> m a -> m a
⎅ (a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM₂
instance (Monad m,MonadError e m) ⇒ MonadError e (UContT m) where
throw ∷ ∀ a. e → UContT m a
throw :: forall a. e -> UContT m a
throw e
e = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
_ ∷ a → m u) → e -> m u
forall a. e -> m a
forall {k} e (m :: k -> *) (a :: k). MonadError e m => e -> m a
throw e
e
catch ∷ ∀ a. UContT m a → (e → UContT m a) → UContT m a
catch :: forall a. UContT m a -> (e -> UContT m a) -> UContT m a
catch UContT m a
xM₁ e -> UContT m a
kk = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
k ∷ a → m u) → do
m u -> (e -> m u) -> m u
forall a. m a -> (e -> m a) -> m a
forall {k} e (m :: k -> *) (a :: k).
MonadError e m =>
m a -> (e -> m a) -> m a
catch ((a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM₁) ((e -> m u) -> m u) -> (e -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ e
e →
(a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k (UContT m a -> m u) -> UContT m a -> m u
forall a b. (a -> b) -> a -> b
$ e -> UContT m a
kk e
e
instance LiftDelay UContT where
liftDelay :: forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> UContT m a) -> UContT m a
liftDelay forall a. (() -> m a) -> m a
delayM () -> UContT m a
xMU = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT (\ a -> m u
𝓀 → (() -> m u) -> m u
forall a. (() -> m a) -> m a
delayM ((() -> m u) -> m u) -> (() -> m u) -> m u
forall a b. (a -> b) -> a -> b
$ \ () → (a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
𝓀 (UContT m a -> m u) -> UContT m a -> m u
forall a b. (a -> b) -> a -> b
$ () -> UContT m a
xMU ())
instance (Monad m,MonadDelay m) ⇒ MonadDelay (UContT m) where
delay :: forall a. (() -> UContT m a) -> UContT m a
delay = (forall a. (() -> m a) -> m a)
-> forall a. (() -> UContT m a) -> UContT m a
forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *).
(LiftDelay t, Monad m) =>
(forall a. (() -> m a) -> m a)
-> forall (a :: k). (() -> t m a) -> t m a
forall (m :: * -> *).
Monad m =>
(forall a. (() -> m a) -> m a)
-> forall a. (() -> UContT m a) -> UContT m a
liftDelay (() -> m a) -> m a
forall a. (() -> m a) -> m a
forall {k} (m :: k -> *) (a :: k).
MonadDelay m =>
(() -> m a) -> m a
delay
instance (Monad m,MonadNondet m) ⇒ MonadNondet (UContT m) where
mzero ∷ ∀ a. UContT m a
mzero :: forall a. UContT m a
mzero = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
_ ∷ a → m u) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadNondet m => m a
mzero
(⊞) ∷ ∀ a. UContT m a → UContT m a → UContT m a
UContT m a
xM₁ ⊞ :: forall a. UContT m a -> UContT m a -> UContT m a
⊞ UContT m a
xM₂ = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
k ∷ a → m u) → do
(a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM₁ m u -> m u -> m u
forall a. m a -> m a -> m a
forall {k} (m :: k -> *) (a :: k).
MonadNondet m =>
m a -> m a -> m a
⊞ (a -> m u) -> UContT m a -> m u
forall {k} (u :: k) (m :: k -> *) a.
(a -> m u) -> UContT m a -> m u
runUContT a -> m u
k UContT m a
xM₂
instance (Monad m,MonadTop m) ⇒ MonadTop (UContT m) where
mtop ∷ ∀ a. UContT m a
mtop :: forall a. UContT m a
mtop = (forall u. (a -> m u) -> m u) -> UContT m a
forall {k} (m :: k -> *) a.
(forall (u :: k). (a -> m u) -> m u) -> UContT m a
UContT ((forall u. (a -> m u) -> m u) -> UContT m a)
-> (forall u. (a -> m u) -> m u) -> UContT m a
forall a b. (a -> b) -> a -> b
HS.$ \ (a -> m u
_ ∷ a → m u) → m u
forall a. m a
forall {k} (m :: k -> *) (a :: k). MonadTop m => m a
mtop
newtype RWST r o s m a = RWST { forall r o s (m :: * -> *) a.
RWST r o s m a -> ReaderT r (WriterT o (StateT s m)) a
unRWST ∷ ReaderT r (WriterT o (StateT s m)) a }
deriving
( (forall a b. (a -> b) -> RWST r o s m a -> RWST r o s m b)
-> Functor (RWST r o s m)
forall a b. (a -> b) -> RWST r o s m a -> RWST r o s m b
forall r o s (m :: * -> *) a b.
Functor m =>
(a -> b) -> RWST r o s m a -> RWST r o s m b
forall (t :: * -> *).
(forall a b. (a -> b) -> t a -> t b) -> Functor t
$cmap :: forall r o s (m :: * -> *) a b.
Functor m =>
(a -> b) -> RWST r o s m a -> RWST r o s m b
map :: forall a b. (a -> b) -> RWST r o s m a -> RWST r o s m b
Functor,(forall a. a -> RWST r o s m a) -> Return (RWST r o s m)
forall a. a -> RWST r o s m a
forall r o s (m :: * -> *) a.
(Return m, Null o) =>
a -> RWST r o s m a
forall (m :: * -> *). (forall a. a -> m a) -> Return m
$creturn :: forall r o s (m :: * -> *) a.
(Return m, Null o) =>
a -> RWST r o s m a
return :: forall a. a -> RWST r o s m a
Return,(forall a b.
RWST r o s m a -> (a -> RWST r o s m b) -> RWST r o s m b)
-> Bind (RWST r o s m)
forall a b.
RWST r o s m a -> (a -> RWST r o s m b) -> RWST r o s m b
forall r o s (m :: * -> *) a b.
(Monad m, Append o) =>
RWST r o s m a -> (a -> RWST r o s m b) -> RWST r o s m b
forall (m :: * -> *).
(forall a b. m a -> (a -> m b) -> m b) -> Bind m
$c≫= :: forall r o s (m :: * -> *) a b.
(Monad m, Append o) =>
RWST r o s m a -> (a -> RWST r o s m b) -> RWST r o s m b
≫= :: forall a b.
RWST r o s m a -> (a -> RWST r o s m b) -> RWST r o s m b
Bind,Bind (RWST r o s m)
Return (RWST r o s m)
Functor (RWST r o s m)
(Functor (RWST r o s m), Return (RWST r o s m),
Bind (RWST r o s m)) =>
Monad (RWST r o s m)
forall r o s (m :: * -> *).
(Null o, Monad m, Append o) =>
Bind (RWST r o s m)
forall r o s (m :: * -> *).
(Null o, Monad m, Append o) =>
Return (RWST r o s m)
forall r o s (m :: * -> *).
(Null o, Monad m, Append o) =>
Functor (RWST r o s m)
forall (m :: * -> *). (Functor m, Return m, Bind m) => Monad m
Monad
, (forall a. IO a -> RWST r o s m a) -> MonadIO (RWST r o s m)
forall a. IO a -> RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadIO m) =>
IO a -> RWST r o s m a
forall (m :: * -> *). (forall a. IO a -> m a) -> MonadIO m
$cio :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadIO m) =>
IO a -> RWST r o s m a
io :: forall a. IO a -> RWST r o s m a
MonadIO
, MonadReader r,MonadWriter o,MonadState s
, (forall a. RWST r o s m a)
-> (forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a)
-> MonadFail (RWST r o s m)
forall a. RWST r o s m a
forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadFail m) =>
RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadFail m) =>
RWST r o s m a -> RWST r o s m a -> RWST r o s m a
forall {k} (m :: k -> *).
(forall (a :: k). m a)
-> (forall (a :: k). m a -> m a -> m a) -> MonadFail m
$cabort :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadFail m) =>
RWST r o s m a
abort :: forall a. RWST r o s m a
$c⎅ :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadFail m) =>
RWST r o s m a -> RWST r o s m a -> RWST r o s m a
⎅ :: forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a
MonadFail,MonadError e
, (forall a. (() -> RWST r o s m a) -> RWST r o s m a)
-> MonadDelay (RWST r o s m)
forall a. (() -> RWST r o s m a) -> RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadDelay m) =>
(() -> RWST r o s m a) -> RWST r o s m a
forall {k} (m :: k -> *).
(forall (a :: k). (() -> m a) -> m a) -> MonadDelay m
$cdelay :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadDelay m) =>
(() -> RWST r o s m a) -> RWST r o s m a
delay :: forall a. (() -> RWST r o s m a) -> RWST r o s m a
MonadDelay
, (forall a. RWST r o s m a)
-> (forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a)
-> MonadNondet (RWST r o s m)
forall a. RWST r o s m a
forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadNondet m) =>
RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadNondet m) =>
RWST r o s m a -> RWST r o s m a -> RWST r o s m a
forall {k} (m :: k -> *).
(forall (a :: k). m a)
-> (forall (a :: k). m a -> m a -> m a) -> MonadNondet m
$cmzero :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadNondet m) =>
RWST r o s m a
mzero :: forall a. RWST r o s m a
$c⊞ :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadNondet m) =>
RWST r o s m a -> RWST r o s m a -> RWST r o s m a
⊞ :: forall a. RWST r o s m a -> RWST r o s m a -> RWST r o s m a
MonadNondet,(forall a. RWST r o s m a) -> MonadTop (RWST r o s m)
forall a. RWST r o s m a
forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadTop m) =>
RWST r o s m a
forall {k} (m :: k -> *). (forall (a :: k). m a) -> MonadTop m
$cmtop :: forall r o s (m :: * -> *) a.
(Monad m, Monoid o, MonadTop m) =>
RWST r o s m a
mtop :: forall a. RWST r o s m a
MonadTop
)
mkRWST ∷ ∀ r o s m a. (Monad m) ⇒ (r → s → m (s ∧ o ∧ a)) → RWST r o s m a
mkRWST :: forall r o s (m :: * -> *) a.
Monad m =>
(r -> s -> m ((s ∧ o) ∧ a)) -> RWST r o s m a
mkRWST r -> s -> m ((s ∧ o) ∧ a)
f = ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
forall r o s (m :: * -> *) a.
ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
RWST (ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a)
-> ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
forall a b. (a -> b) -> a -> b
$ (r -> WriterT o (StateT s m) a)
-> ReaderT r (WriterT o (StateT s m)) a
forall {k} r (m :: k -> *) (a :: k). (r -> m a) -> ReaderT r m a
ReaderT ((r -> WriterT o (StateT s m) a)
-> ReaderT r (WriterT o (StateT s m)) a)
-> (r -> WriterT o (StateT s m) a)
-> ReaderT r (WriterT o (StateT s m)) a
forall a b. (a -> b) -> a -> b
$ \ r
r → StateT s m (o ∧ a) -> WriterT o (StateT s m) a
forall o (m :: * -> *) a. m (o ∧ a) -> WriterT o m a
WriterT (StateT s m (o ∧ a) -> WriterT o (StateT s m) a)
-> StateT s m (o ∧ a) -> WriterT o (StateT s m) a
forall a b. (a -> b) -> a -> b
$ (s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a)
forall s (m :: * -> *) a. (s -> m (s ∧ a)) -> StateT s m a
StateT ((s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a))
-> (s -> m (s ∧ (o ∧ a))) -> StateT s m (o ∧ a)
forall a b. (a -> b) -> a -> b
$ \ s
s → do
(s
s' :* o
o :* a
a) ← r -> s -> m ((s ∧ o) ∧ a)
f r
r s
s
(s ∧ (o ∧ a)) -> m (s ∧ (o ∧ a))
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s' s -> (o ∧ a) -> s ∧ (o ∧ a)
forall a b. a -> b -> a ∧ b
:* (o
o o -> a -> o ∧ a
forall a b. a -> b -> a ∧ b
:* a
a))
runRWST ∷ ∀ r o s m a. (Monad m) ⇒ r → s → RWST r o s m a → m (s ∧ o ∧ a)
runRWST :: forall r o s (m :: * -> *) a.
Monad m =>
r -> s -> RWST r o s m a -> m ((s ∧ o) ∧ a)
runRWST r
r s
s RWST r o s m a
xM = do
(s
s' :* (o
o :* a
a)) ← StateT s m (o ∧ a) -> s -> m (s ∧ (o ∧ a))
forall s (m :: * -> *) a. StateT s m a -> s -> m (s ∧ a)
unStateT (WriterT o (StateT s m) a -> StateT s m (o ∧ a)
forall o (m :: * -> *) a. WriterT o m a -> m (o ∧ a)
unWriterT (ReaderT r (WriterT o (StateT s m)) a
-> r -> WriterT o (StateT s m) a
forall {k} r (m :: k -> *) (a :: k). ReaderT r m a -> r -> m a
unReaderT (RWST r o s m a -> ReaderT r (WriterT o (StateT s m)) a
forall r o s (m :: * -> *) a.
RWST r o s m a -> ReaderT r (WriterT o (StateT s m)) a
unRWST RWST r o s m a
xM) r
r)) s
s
((s ∧ o) ∧ a) -> m ((s ∧ o) ∧ a)
forall a. a -> m a
forall (m :: * -> *) a. Return m => a -> m a
return (s
s' s -> o -> s ∧ o
forall a b. a -> b -> a ∧ b
:* o
o (s ∧ o) -> a -> (s ∧ o) ∧ a
forall a b. a -> b -> a ∧ b
:* a
a)
evalRWST ∷ ∀ r o s m a. (Monad m) ⇒ r → s → RWST r o s m a → m a
evalRWST :: forall r o s (m :: * -> *) a.
Monad m =>
r -> s -> RWST r o s m a -> m a
evalRWST r
r s
s = (((s ∧ o) ∧ a) -> a) -> m ((s ∧ o) ∧ a) -> m a
forall a b. (a -> b) -> m a -> m b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ((s ∧ o) ∧ a) -> a
forall a b. (a ∧ b) -> b
snd (m ((s ∧ o) ∧ a) -> m a)
-> (RWST r o s m a -> m ((s ∧ o) ∧ a)) -> RWST r o s m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ r -> s -> RWST r o s m a -> m ((s ∧ o) ∧ a)
forall r o s (m :: * -> *) a.
Monad m =>
r -> s -> RWST r o s m a -> m ((s ∧ o) ∧ a)
runRWST r
r s
s
instance (Monoid o) ⇒ Functor2 (RWST r o s) where
map2 ∷ ∀ f₁ f₂. (∀ a. f₁ a → f₂ a) → (∀ a. RWST r o s f₁ a → RWST r o s f₂ a)
map2 :: forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> RWST r o s t →⁻ RWST r o s u
map2 forall a. f₁ a -> f₂ a
f = ReaderT r (WriterT o (StateT s f₂)) a -> RWST r o s f₂ a
forall r o s (m :: * -> *) a.
ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
RWST (ReaderT r (WriterT o (StateT s f₂)) a -> RWST r o s f₂ a)
-> (ReaderT r (WriterT o (StateT s f₁)) a
-> ReaderT r (WriterT o (StateT s f₂)) a)
-> ReaderT r (WriterT o (StateT s f₁)) a
-> RWST r o s f₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (WriterT o (StateT s f₁) →⁻ WriterT o (StateT s f₂))
-> ReaderT r (WriterT o (StateT s f₁))
→⁻ ReaderT r (WriterT o (StateT s f₂))
forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> ReaderT r t →⁻ ReaderT r u
forall (w :: (* -> *) -> * -> *) (t :: * -> *) (u :: * -> *).
Functor2 w =>
(t →⁻ u) -> w t →⁻ w u
map2 ((StateT s f₁ →⁻ StateT s f₂)
-> WriterT o (StateT s f₁) →⁻ WriterT o (StateT s f₂)
forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> WriterT o t →⁻ WriterT o u
forall (w :: (* -> *) -> * -> *) (t :: * -> *) (u :: * -> *).
Functor2 w =>
(t →⁻ u) -> w t →⁻ w u
map2 ((forall a. f₁ a -> f₂ a) -> StateT s f₁ →⁻ StateT s f₂
forall (t :: * -> *) (u :: * -> *).
(t →⁻ u) -> StateT s t →⁻ StateT s u
forall (w :: (* -> *) -> * -> *) (t :: * -> *) (u :: * -> *).
Functor2 w =>
(t →⁻ u) -> w t →⁻ w u
map2 f₁ a -> f₂ a
forall a. f₁ a -> f₂ a
f)) (ReaderT r (WriterT o (StateT s f₁)) a -> RWST r o s f₂ a)
-> (RWST r o s f₁ a -> ReaderT r (WriterT o (StateT s f₁)) a)
-> RWST r o s f₁ a
-> RWST r o s f₂ a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ RWST r o s f₁ a -> ReaderT r (WriterT o (StateT s f₁)) a
forall r o s (m :: * -> *) a.
RWST r o s m a -> ReaderT r (WriterT o (StateT s m)) a
unRWST
instance (RWST r o s) ⇄⁼ (ReaderT r ⊡ WriterT o ⊡ StateT s) where
isoto3 ∷ ∀ f a. RWST r o s f a → (ReaderT r ⊡ WriterT o ⊡ StateT s) f a
isoto3 :: RWST r o s →⁼ ((ReaderT r ⊡ WriterT o) ⊡ StateT s)
isoto3 = (⊡) (ReaderT r) (WriterT o) (StateT s f) a
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
forall (t₁ :: (* -> *) -> * -> *) (t₂ :: (* -> *) -> * -> *)
(m :: * -> *) a.
t₁ (t₂ m) a -> (⊡) t₁ t₂ m a
Compose2 ((⊡) (ReaderT r) (WriterT o) (StateT s f) a
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a)
-> (ReaderT r (WriterT o (StateT s f)) a
-> (⊡) (ReaderT r) (WriterT o) (StateT s f) a)
-> ReaderT r (WriterT o (StateT s f)) a
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ ReaderT r (WriterT o (StateT s f)) a
-> (⊡) (ReaderT r) (WriterT o) (StateT s f) a
forall (t₁ :: (* -> *) -> * -> *) (t₂ :: (* -> *) -> * -> *)
(m :: * -> *) a.
t₁ (t₂ m) a -> (⊡) t₁ t₂ m a
Compose2 (ReaderT r (WriterT o (StateT s f)) a
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a)
-> (RWST r o s f a -> ReaderT r (WriterT o (StateT s f)) a)
-> RWST r o s f a
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ RWST r o s f a -> ReaderT r (WriterT o (StateT s f)) a
forall r o s (m :: * -> *) a.
RWST r o s m a -> ReaderT r (WriterT o (StateT s m)) a
unRWST
isofr3 ∷ ∀ f a. (ReaderT r ⊡ WriterT o ⊡ StateT s) f a → RWST r o s f a
isofr3 :: ((ReaderT r ⊡ WriterT o) ⊡ StateT s) →⁼ RWST r o s
isofr3 = ReaderT r (WriterT o (StateT s f)) a -> RWST r o s f a
forall r o s (m :: * -> *) a.
ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
RWST (ReaderT r (WriterT o (StateT s f)) a -> RWST r o s f a)
-> ((⊡) (ReaderT r) (WriterT o) (StateT s f) a
-> ReaderT r (WriterT o (StateT s f)) a)
-> (⊡) (ReaderT r) (WriterT o) (StateT s f) a
-> RWST r o s f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (⊡) (ReaderT r) (WriterT o) (StateT s f) a
-> ReaderT r (WriterT o (StateT s f)) a
forall (t₁ :: (* -> *) -> * -> *) (t₂ :: (* -> *) -> * -> *)
(m :: * -> *) a.
(⊡) t₁ t₂ m a -> t₁ (t₂ m) a
unCompose2 ((⊡) (ReaderT r) (WriterT o) (StateT s f) a -> RWST r o s f a)
-> ((⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
-> (⊡) (ReaderT r) (WriterT o) (StateT s f) a)
-> (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
-> RWST r o s f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ (⊡) (ReaderT r ⊡ WriterT o) (StateT s) f a
-> (⊡) (ReaderT r) (WriterT o) (StateT s f) a
forall (t₁ :: (* -> *) -> * -> *) (t₂ :: (* -> *) -> * -> *)
(m :: * -> *) a.
(⊡) t₁ t₂ m a -> t₁ (t₂ m) a
unCompose2
instance (Monoid o) ⇒ Transformer (RWST r o s) where
lift :: forall (m :: * -> *) a. Monad m => m a -> RWST r o s m a
lift = ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
forall r o s (m :: * -> *) a.
ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a
RWST (ReaderT r (WriterT o (StateT s m)) a -> RWST r o s m a)
-> (WriterT o (StateT s m) a
-> ReaderT r (WriterT o (StateT s m)) a)
-> WriterT o (StateT s m) a
-> RWST r o s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ WriterT o (StateT s m) a -> ReaderT r (WriterT o (StateT s m)) a
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(Transformer t, Monad m) =>
m a -> t m a
lift (WriterT o (StateT s m) a -> RWST r o s m a)
-> (StateT s m a -> WriterT o (StateT s m) a)
-> StateT s m a
-> RWST r o s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ StateT s m a -> WriterT o (StateT s m) a
forall (m :: * -> *) a. Monad m => m a -> WriterT o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(Transformer t, Monad m) =>
m a -> t m a
lift (StateT s m a -> RWST r o s m a)
-> (m a -> StateT s m a) -> m a -> RWST r o s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
∘ m a -> StateT s m a
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(Transformer t, Monad m) =>
m a -> t m a
lift
deriving instance (Func Null m,Null o,Null s,Null a) ⇒ Null (RWST r o s m a)
deriving instance (Func Append m,Append o,Append s,Append a) ⇒ Append (RWST r o s m a)
deriving instance
( Func Null m
, Func Append m
, Monoid o,Monoid s,Monoid a
)
⇒ Monoid (RWST r o s m a)
type RWS r o s = RWST r o s ID
mkRWS ∷ ∀ r o s a. (r → s → (s ∧ o ∧ a)) → RWS r o s a
mkRWS :: forall r o s a. (r -> s -> (s ∧ o) ∧ a) -> RWS r o s a
mkRWS r -> s -> (s ∧ o) ∧ a
f = (r -> s -> ID ((s ∧ o) ∧ a)) -> RWST r o s ID a
forall r o s (m :: * -> *) a.
Monad m =>
(r -> s -> m ((s ∧ o) ∧ a)) -> RWST r o s m a
mkRWST (\ r
r s
s → ((s ∧ o) ∧ a) -> ID ((s ∧ o) ∧ a)
forall a. a -> ID a
ID (((s ∧ o) ∧ a) -> ID ((s ∧ o) ∧ a))
-> ((s ∧ o) ∧ a) -> ID ((s ∧ o) ∧ a)
forall a b. (a -> b) -> a -> b
$ r -> s -> (s ∧ o) ∧ a
f r
r s
s)
runRWS ∷ ∀ r o s a. r → s → RWS r o s a → s ∧ o ∧ a
runRWS :: forall r o s a. r -> s -> RWS r o s a -> (s ∧ o) ∧ a
runRWS r
r s
s RWS r o s a
xM = ID ((s ∧ o) ∧ a) -> (s ∧ o) ∧ a
forall a. ID a -> a
unID (ID ((s ∧ o) ∧ a) -> (s ∧ o) ∧ a)
-> ID ((s ∧ o) ∧ a) -> (s ∧ o) ∧ a
forall a b. (a -> b) -> a -> b
$ r -> s -> RWS r o s a -> ID ((s ∧ o) ∧ a)
forall r o s (m :: * -> *) a.
Monad m =>
r -> s -> RWST r o s m a -> m ((s ∧ o) ∧ a)
runRWST r
r s
s RWS r o s a
xM
evalRWS ∷ ∀ r o s a. r → s → RWS r o s a → a
evalRWS :: forall r o s a. r -> s -> RWS r o s a -> a
evalRWS r
r s
s RWS r o s a
xM = ID a -> a
forall a. ID a -> a
unID (ID a -> a) -> ID a -> a
forall a b. (a -> b) -> a -> b
$ r -> s -> RWS r o s a -> ID a
forall r o s (m :: * -> *) a.
Monad m =>
r -> s -> RWST r o s m a -> m a
evalRWST r
r s
s RWS r o s a
xM