Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

chrisdone-archive/conditions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conditions

Conditions for Haskell.

Haddocks

In this library, a condition does not unwind the call stack, instead it makes a non-local transfer of control to the condition handler which can permit the handler to continue the computation with different conditions, retry, signal a new condition, or abort with an exception.

Motivation

In languages with comprehensive condition systems like Common Lisp, it is possible for the development environment to reify conditions into something meaningful to allow the programmer to take some corrective action without bailing out the whole program. Examples:

  • In the case of failing to open a file during a long-running computation, the IDE can prompt the developer to provide another file name, retry, abort, etc.
  • Parsing a CSV and encountering a line that does not parse can allow the developer to attempt to re-parse, change the parsing function on the fly to suite new discovered requirements or substitute a value to be used for that row, or ignore it.

See the examples/ directory for code versions of these examples.

Library

A condition must be an instance of the Condition class:

class (Exception c) => Condition c r | c -> r

The r states the return value of the code signalling the condition. Signalling is done with the signal function:

signal :: (Handlers,Condition c r) => c -> r

And handling is done using handler:

handler :: (Handlers,Condition c r)
        => (Handlers => c -> r) -- ^ Condition handler.
        -> (Handlers => a)      -- ^ Scope of the condition handler.
        -> a

In the absence of any handlers, a signal is thrown as an exception.

Releases

No releases published

Packages

No packages published