essence-of-live-coding-0.2.6: General purpose live coding framework
Safe HaskellNone



Live programs in the ExceptT e m monad can stop execution by throwing an exception e.

Handling these exceptions is done by realising that live programs in fact form a monad in the exception type. The interface is analogous to CellExcept.



newtype LiveProgramExcept m e Source #

A live program that can throw an exception.

  • m: The monad in which the live program operates.
  • e: The type of exceptions the live program can eventually throw.

LiveProgramExcept is a monad in the exception type. This means that it is possible to chain several live programs, where later programs can handle the exceptions thrown by the earlier ones. return plays the role of directly throwing an exception. (>>=) lets a handler decide which program to handle the exception with.

The interface is the basically the same as CellExcept, and it is in fact a newtype around it.




runLiveProgramExcept :: Monad m => LiveProgramExcept m e -> LiveProgram (ExceptT e m) Source #

Execute a LiveProgramExcept, throwing its exceptions in the ExceptT monad.

try :: (Data e, Finite e, Functor m) => LiveProgram (ExceptT e m) -> LiveProgramExcept m e Source #

Lift a LiveProgram into the LiveProgramExcept monad.

Similar to try. This will execute the live program until it throws an exception.

safely :: Monad m => LiveProgramExcept m Void -> LiveProgram m Source #

Safely convert to LivePrograms.

If the type of possible exceptions is empty, no exceptions can be thrown, and thus we can safely assume that it is a LiveProgram in m.

safe :: Monad m => LiveProgram m -> LiveProgramExcept m Void Source #

Run a LiveProgram as a LiveProgramExcept.

This is always safe in the sense that it has no exceptions.

once :: (Monad m, Data e, Finite e) => m e -> LiveProgramExcept m e Source #

Run a monadic action and immediately raise its result as an exception.

foreverELiveProgram Source #


:: (Data e, Monad m) 
=> e

The loop initialisation

-> LiveProgramExcept (ReaderT e m) e

The live program to execute indefinitely

-> LiveProgram m 

Run a LiveProgramExcept in a loop.

In the additional 'ReaderT e' context, you can read the last thrown exception. (For the first iteration, e is set to the first argument to foreverELiveProgram.)

This way, you can create an infinite loop, with the exception as the loop variable.

foreverCLiveProgram :: (Data e, Monad m) => LiveProgramExcept m e -> LiveProgram m Source #

Run a LiveProgramExcept in a loop, discarding the exception.