@hackage / tagged-exception-core

Reflect exceptions using phantom types.

Latest2.2.0.0

About

Metadata

  • Last updated , by PeterTrsko
  • License BSD-3-Clause
  • Categories Monads
  • Maintained by: peter.trsko@gmail.com

  • Lottery factor: 0

Links

Installation

Package Flags

Use the -f option with cabal commands to enable flags

    pedantic (off by default)

    Pass additional flags to GHC.

Readme

Tagged Exception Core

Hackage Hackage Dependencies Haskell Programming Language BSD3 License

Build

Description

Reflect exceptions using phantom types. This library provides core API and others may build on top of it.

Usage Example

Example of reflecting reised exception in type:

{-# LANGUAGE DeriveDataTypeable #-}

import Control.Exception (Exception)

import Control.Monad.TaggedException (Throws)
import qualified Control.Monad.TaggedException as E (liftT, throw)
import Data.Typeable (Typeable)


data NotReady = NotReady String
    deriving (Show, Typeable)
        -- Both required by Exception class

instance Exception NotReady

myFunction :: Input -> Throws NotReady IO Output
myFunction input = do

    -- ... some stuff ...

    -- isReady :: Input -> IO Bool
    ready <- E.liftT $ isReady input
    unless ready
        . E.throw $ NotReady "Resource of myFunction is not ready."

    -- ... some other stuff ...

License

The BSD 3-Clause License, see LICENSE file for details.

Contributions

Contributions, pull requests and bug reports are welcome! Please don't be afraid to contact author using GitHub or by e-mail.