Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides exception handling, and thus control flow, to synchronous signal functions.
The API presented here closely follows automaton
's Data.Automaton.Trans.Except,
and reexports everything needed from there.
Synopsis
- type ClSFExcept cl a b m e = AutomatonExcept a b (ReaderT (TimeInfo cl) m) e
- type BehaviourFExcept time a b m e = forall cl. time ~ Time cl => ClSFExcept cl a b m e
- type BehaviorFExcept time a b m e = BehaviourFExcept time a b m e
- pass :: Monad m => Automaton (ExceptT e m) a a
- step :: Monad m => (a -> m (b, e)) -> ClSFExcept cl a b m e
- throwOnCond :: Monad m => (a -> Bool) -> e -> ClSF (ExceptT e m) cl a a
- throwOnCondM :: Monad m => (a -> m Bool) -> e -> ClSF (ExceptT e m) cl a a
- throwOn :: Monad m => e -> ClSF (ExceptT e m) cl Bool ()
- throwOn' :: Monad m => ClSF (ExceptT e m) cl (Bool, e) ()
- throwMaybe :: Monad m => ClSF (ExceptT e m) cl (Maybe e) (Maybe a)
- throwS :: Monad m => ClSF (ExceptT e m) cl e a
- throw :: Monad m => e -> Automaton (ExceptT e m) a b
- try :: Monad m => ClSF (ExceptT e m) cl a b -> ClSFExcept cl a b m e
- once :: Monad m => (a -> m e) -> ClSFExcept cl a b m e
- once_ :: Monad m => m e -> ClSFExcept cl a b m e
- runClSFExcept :: Monad m => ClSFExcept cl a b m e -> ClSF (ExceptT e m) cl a b
- module Control.Monad.Trans.Except
- safe :: forall (m :: Type -> Type) a b e. Monad m => Automaton m a b -> AutomatonExcept a b m e
- safely :: forall (m :: Type -> Type) a b. Monad m => AutomatonExcept a b m Void -> Automaton m a b
- exceptS :: forall (m :: Type -> Type) e a b. (Functor m, Monad m) => Automaton (ExceptT e m) a b -> Automaton m a (Either e b)
- runAutomatonExcept :: forall (m :: Type -> Type) a b e. Monad m => AutomatonExcept a b m e -> Automaton (ExceptT e m) a b
- currentInput :: forall (m :: Type -> Type) e b. Monad m => AutomatonExcept e b m e
Documentation
type ClSFExcept cl a b m e = AutomatonExcept a b (ReaderT (TimeInfo cl) m) e Source #
A synchronous exception-throwing signal function.
It is based on a newtype
from automaton
, AutomatonExcept
,
to exhibit a monad interface in the exception type.
return
then corresponds to throwing an exception,
and (>>=)
is exception handling.
(For more information, see the documentation of AutomatonExcept
.)
cl
: The clock on which the signal function ticksa
: The input typeb
: The output typem
: The monad that the signal function may take side effects ine
: The type of exceptions that can be thrown
type BehaviourFExcept time a b m e = forall cl. time ~ Time cl => ClSFExcept cl a b m e Source #
A clock polymorphic ClSFExcept
,
or equivalently an exception-throwing behaviour.
Any clock with time domain time
may occur.
type BehaviorFExcept time a b m e = BehaviourFExcept time a b m e Source #
Compatibility to U.S. american spelling.
step :: Monad m => (a -> m (b, e)) -> ClSFExcept cl a b m e Source #
Advances a single tick with the given Kleisli arrow, and then throws an exception.
throwOnCond :: Monad m => (a -> Bool) -> e -> ClSF (ExceptT e m) cl a a Source #
Throw the exception e
whenever the function evaluates to True
.
throwOnCondM :: Monad m => (a -> m Bool) -> e -> ClSF (ExceptT e m) cl a a Source #
Variant of throwOnCond
for Kleisli arrows.
Throws the exception when the input is True
.
throwOn :: Monad m => e -> ClSF (ExceptT e m) cl Bool () Source #
Throw the given exception when the Bool
turns true.
throwOn' :: Monad m => ClSF (ExceptT e m) cl (Bool, e) () Source #
Variant of throwOn
, where the exception can vary every tick.
throwMaybe :: Monad m => ClSF (ExceptT e m) cl (Maybe e) (Maybe a) Source #
When the input is Just e
, throw the exception e
.
once :: Monad m => (a -> m e) -> ClSFExcept cl a b m e Source #
Within the same tick, perform a monadic action, and immediately throw the value as an exception.
runClSFExcept :: Monad m => ClSFExcept cl a b m e -> ClSF (ExceptT e m) cl a b Source #
Leave the monad context, to use the ClSFExcept
as an Arrow
.
module Control.Monad.Trans.Except
safe :: forall (m :: Type -> Type) a b e. Monad m => Automaton m a b -> AutomatonExcept a b m e #
An Automaton
without an ExceptT
layer never throws an exception, and can
thus have an arbitrary exception type.
In particular, the exception type can be Void
, so it can be used as the last statement in an AutomatonExcept
do
-block.
See safely
for an example.
safely :: forall (m :: Type -> Type) a b. Monad m => AutomatonExcept a b m Void -> Automaton m a b #
If no exception can occur, the Automaton
can be executed without the ExceptT
layer.
Used to exit the AutomatonExcept
context, often in combination with safe
:
automaton = safely $ do e <- try someAutomaton once $ input -> putStrLn $ "Whoops, something happened when receiving input " ++ show input ++ ": " ++ show e ++ ", but I'll continue now." safe fallbackAutomaton
exceptS :: forall (m :: Type -> Type) e a b. (Functor m, Monad m) => Automaton (ExceptT e m) a b -> Automaton m a (Either e b) #
Escape an ExceptT
layer by outputting the exception whenever it occurs.
If an exception occurs, the current state is is tested again on the next input.
runAutomatonExcept :: forall (m :: Type -> Type) a b e. Monad m => AutomatonExcept a b m e -> Automaton (ExceptT e m) a b #
currentInput :: forall (m :: Type -> Type) e b. Monad m => AutomatonExcept e b m e #
Immediately throw the current input as an exception.
Useful inside AutomatonExcept
if you don't want to advance a further step in execution,
but first see what the current input is before continuing.