Giter VIP home page Giter VIP logo

conditions's Introduction

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.

conditions's People

Contributors

chrisdone avatar jmct avatar

Stargazers

Angus H. avatar  avatar Yoshiki Schmitz avatar Theunis Kotze avatar Quinten Palmer avatar Karol Marcjan avatar Alexander Wang avatar Shane Celis avatar  avatar Emily avatar Daniel Kahlenberg avatar Pascal Hartig avatar Yuan Chuan avatar  avatar

Watchers

 avatar Tomáš Jakl avatar James Cloos avatar Emily avatar  avatar

Forkers

jmct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.