{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
module LiveCoding.LiveProgram.Except where
import Control.Monad (ap, liftM)
import Data.Data
import Data.Void (Void)
import Control.Monad.Trans.Except
import Control.Monad.Trans.Reader
import LiveCoding.Cell (constM, hoistCell, liveCell, toLiveCell)
import LiveCoding.CellExcept (CellExcept, once_, runCellExcept)
import qualified LiveCoding.CellExcept as CellExcept
import LiveCoding.Exceptions.Finite (Finite)
import LiveCoding.Forever
import LiveCoding.LiveProgram
newtype LiveProgramExcept m e = LiveProgramExcept
{forall (m :: * -> *) e.
LiveProgramExcept m e -> CellExcept () () m e
unLiveProgramExcept :: CellExcept () () m e}
deriving (forall a b. a -> LiveProgramExcept m b -> LiveProgramExcept m a
forall a b.
(a -> b) -> LiveProgramExcept m a -> LiveProgramExcept m b
forall (m :: * -> *) a b.
Monad m =>
a -> LiveProgramExcept m b -> LiveProgramExcept m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> LiveProgramExcept m a -> LiveProgramExcept m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> LiveProgramExcept m b -> LiveProgramExcept m a
$c<$ :: forall (m :: * -> *) a b.
Monad m =>
a -> LiveProgramExcept m b -> LiveProgramExcept m a
fmap :: forall a b.
(a -> b) -> LiveProgramExcept m a -> LiveProgramExcept m b
$cfmap :: forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> LiveProgramExcept m a -> LiveProgramExcept m b
Functor, forall a. a -> LiveProgramExcept m a
forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m a
forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
forall a b.
LiveProgramExcept m (a -> b)
-> LiveProgramExcept m a -> LiveProgramExcept m b
forall a b c.
(a -> b -> c)
-> LiveProgramExcept m a
-> LiveProgramExcept m b
-> LiveProgramExcept m c
forall (m :: * -> *). Monad m => Functor (LiveProgramExcept m)
forall (m :: * -> *) a. Monad m => a -> LiveProgramExcept m a
forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m a
forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m (a -> b)
-> LiveProgramExcept m a -> LiveProgramExcept m b
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> LiveProgramExcept m a
-> LiveProgramExcept m b
-> LiveProgramExcept m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m a
$c<* :: forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m a
*> :: forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
$c*> :: forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
liftA2 :: forall a b c.
(a -> b -> c)
-> LiveProgramExcept m a
-> LiveProgramExcept m b
-> LiveProgramExcept m c
$cliftA2 :: forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> LiveProgramExcept m a
-> LiveProgramExcept m b
-> LiveProgramExcept m c
<*> :: forall a b.
LiveProgramExcept m (a -> b)
-> LiveProgramExcept m a -> LiveProgramExcept m b
$c<*> :: forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m (a -> b)
-> LiveProgramExcept m a -> LiveProgramExcept m b
pure :: forall a. a -> LiveProgramExcept m a
$cpure :: forall (m :: * -> *) a. Monad m => a -> LiveProgramExcept m a
Applicative, forall a. a -> LiveProgramExcept m a
forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
forall a b.
LiveProgramExcept m a
-> (a -> LiveProgramExcept m b) -> LiveProgramExcept m b
forall (m :: * -> *). Monad m => Applicative (LiveProgramExcept m)
forall (m :: * -> *) a. Monad m => a -> LiveProgramExcept m a
forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> (a -> LiveProgramExcept m b) -> LiveProgramExcept m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> LiveProgramExcept m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> LiveProgramExcept m a
>> :: forall a b.
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> LiveProgramExcept m b -> LiveProgramExcept m b
>>= :: forall a b.
LiveProgramExcept m a
-> (a -> LiveProgramExcept m b) -> LiveProgramExcept m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
LiveProgramExcept m a
-> (a -> LiveProgramExcept m b) -> LiveProgramExcept m b
Monad)
runLiveProgramExcept ::
Monad m =>
LiveProgramExcept m e ->
LiveProgram (ExceptT e m)
runLiveProgramExcept :: forall (m :: * -> *) e.
Monad m =>
LiveProgramExcept m e -> LiveProgram (ExceptT e m)
runLiveProgramExcept LiveProgramExcept {CellExcept () () m e
unLiveProgramExcept :: CellExcept () () m e
unLiveProgramExcept :: forall (m :: * -> *) e.
LiveProgramExcept m e -> CellExcept () () m e
..} = forall (m :: * -> *). Monad m => Cell m () () -> LiveProgram m
liveCell forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b e.
Monad m =>
CellExcept a b m e -> Cell (ExceptT e m) a b
runCellExcept CellExcept () () m e
unLiveProgramExcept
try ::
(Data e, Finite e, Functor m) =>
LiveProgram (ExceptT e m) ->
LiveProgramExcept m e
try :: forall e (m :: * -> *).
(Data e, Finite e, Functor m) =>
LiveProgram (ExceptT e m) -> LiveProgramExcept m e
try = forall (m :: * -> *) e.
CellExcept () () m e -> LiveProgramExcept m e
LiveProgramExcept forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (m :: * -> *) a b.
(Data e, Finite e) =>
Cell (ExceptT e m) a b -> CellExcept a b m e
CellExcept.try forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Functor m => LiveProgram m -> Cell m () ()
toLiveCell
safely ::
Monad m =>
LiveProgramExcept m Void ->
LiveProgram m
safely :: forall (m :: * -> *).
Monad m =>
LiveProgramExcept m Void -> LiveProgram m
safely = forall (m :: * -> *). Monad m => Cell m () () -> LiveProgram m
liveCell forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
CellExcept a b m Void -> Cell m a b
CellExcept.safely forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e.
LiveProgramExcept m e -> CellExcept () () m e
unLiveProgramExcept
safe ::
Monad m =>
LiveProgram m ->
LiveProgramExcept m Void
safe :: forall (m :: * -> *).
Monad m =>
LiveProgram m -> LiveProgramExcept m Void
safe = forall (m :: * -> *) e.
CellExcept () () m e -> LiveProgramExcept m e
LiveProgramExcept forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
Cell m a b -> CellExcept a b m Void
CellExcept.safe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Functor m => LiveProgram m -> Cell m () ()
toLiveCell
once :: (Monad m, Data e, Finite e) => m e -> LiveProgramExcept m e
once :: forall (m :: * -> *) e.
(Monad m, Data e, Finite e) =>
m e -> LiveProgramExcept m e
once = forall (m :: * -> *) e.
CellExcept () () m e -> LiveProgramExcept m e
LiveProgramExcept forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a arbitrary.
(Monad m, Data e, Finite e) =>
m e -> CellExcept a arbitrary m e
once_
foreverELiveProgram ::
(Data e, Monad m) =>
e ->
LiveProgramExcept (ReaderT e m) e ->
LiveProgram m
foreverELiveProgram :: forall e (m :: * -> *).
(Data e, Monad m) =>
e -> LiveProgramExcept (ReaderT e m) e -> LiveProgram m
foreverELiveProgram e
e LiveProgramExcept {CellExcept () () (ReaderT e m) e
unLiveProgramExcept :: CellExcept () () (ReaderT e m) e
unLiveProgramExcept :: forall (m :: * -> *) e.
LiveProgramExcept m e -> CellExcept () () m e
..} = forall (m :: * -> *). Monad m => Cell m () () -> LiveProgram m
liveCell forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a b.
(Monad m, Data e) =>
e -> Cell (ReaderT e (ExceptT e m)) a b -> Cell m a b
foreverE e
e forall a b. (a -> b) -> a -> b
$ forall (m1 :: * -> *) (m2 :: * -> *) a b.
(forall x. m1 x -> m2 x) -> Cell m1 a b -> Cell m2 a b
hoistCell forall e r (m :: * -> *) a.
ExceptT e (ReaderT r m) a -> ReaderT r (ExceptT e m) a
commute forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b e.
Monad m =>
CellExcept a b m e -> Cell (ExceptT e m) a b
runCellExcept CellExcept () () (ReaderT e m) e
unLiveProgramExcept
where
commute :: ExceptT e (ReaderT r m) a -> ReaderT r (ExceptT e m) a
commute :: forall e r (m :: * -> *) a.
ExceptT e (ReaderT r m) a -> ReaderT r (ExceptT e m) a
commute ExceptT e (ReaderT r m) a
action = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT e (ReaderT r m) a
action)
foreverCLiveProgram ::
(Data e, Monad m) =>
LiveProgramExcept m e ->
LiveProgram m
foreverCLiveProgram :: forall e (m :: * -> *).
(Data e, Monad m) =>
LiveProgramExcept m e -> LiveProgram m
foreverCLiveProgram LiveProgramExcept {CellExcept () () m e
unLiveProgramExcept :: CellExcept () () m e
unLiveProgramExcept :: forall (m :: * -> *) e.
LiveProgramExcept m e -> CellExcept () () m e
..} = forall (m :: * -> *). Monad m => Cell m () () -> LiveProgram m
liveCell forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a b.
(Data e, Monad m) =>
Cell (ExceptT e m) a b -> Cell m a b
foreverC forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b e.
Monad m =>
CellExcept a b m e -> Cell (ExceptT e m) a b
runCellExcept CellExcept () () m e
unLiveProgramExcept