LParse-0.2.3.0: A continuation-based parser library

Copyright(c) Marcus Völker 2017
LicenseMIT
Maintainermarcus.voelker@rwth-aachen.de
Safe HaskellSafe
LanguageHaskell2010

Control.DoubleContinuations

Description

This module describes DoubleContinuations, which are Continuations that may have succeeded or failed. Instead of just taking a single function (a -> r) -> r to execute after the computation has run, a double continuation takes two functions: one to call in case of success and one to call in case of error This allows for easy implementation of exception handling and structuring control flow in a pass/fail manner

Synopsis

Documentation

data DCont r e a Source #

The double continuation. Takes two functions, one to invoke if the computation is successful, one if it errors

Constructors

DCont 

Fields

  • run :: (a -> r) -> (e -> r) -> r
     
Instances
Monad (DCont r e) Source #

Binding a Continuation means running it, then feeding the result into f to generate a new continuation, and running that

Instance details

Defined in Control.DoubleContinuations

Methods

(>>=) :: DCont r e a -> (a -> DCont r e b) -> DCont r e b #

(>>) :: DCont r e a -> DCont r e b -> DCont r e b #

return :: a -> DCont r e a #

fail :: String -> DCont r e a #

Functor (DCont r e) Source #

via Monad/Functor laws

Instance details

Defined in Control.DoubleContinuations

Methods

fmap :: (a -> b) -> DCont r e a -> DCont r e b #

(<$) :: a -> DCont r e b -> DCont r e a #

Applicative (DCont r e) Source #

via Monad/Applicative laws

Instance details

Defined in Control.DoubleContinuations

Methods

pure :: a -> DCont r e a #

(<*>) :: DCont r e (a -> b) -> DCont r e a -> DCont r e b #

liftA2 :: (a -> b -> c) -> DCont r e a -> DCont r e b -> DCont r e c #

(*>) :: DCont r e a -> DCont r e b -> DCont r e b #

(<*) :: DCont r e a -> DCont r e b -> DCont r e a #

Alternative (DCont r e) Source #

An empty alternative just fails with an undefined error. Branching means first trying one, and in case of failure, the other

Instance details

Defined in Control.DoubleContinuations

Methods

empty :: DCont r e a #

(<|>) :: DCont r e a -> DCont r e a -> DCont r e a #

some :: DCont r e a -> DCont r e [a] #

many :: DCont r e a -> DCont r e [a] #

throw Source #

Arguments

:: e

The error to return

-> DCont r e a 

Generates a continuation that always fails. For a continuation that always succeeds, see return

invoke :: DCont (Either e a) e a -> Either e a Source #

Convenience function to run a computation and put the result into an Either (with Left being the error and Right being the success)