Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://hackage.haskell.org/package/control-monad-exception">Control.Monad.Exception</a> library allows strongly typed exceptions to be used in non IO code. This allows functions to throw errors, and easily compose with functions that throw different errors. For example:</p> <pre><code>{-# LANGUAGE RankNTypes, MultiParamTypeClasses, FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} import Prelude hiding (catch) import Control.Monad.Exception data FooException = FooException deriving (Show, Typeable) instance Exception FooException data BarErrors = BarErrors deriving (Show, Typeable) instance Exception BarErrors data BazErrors = BazErrors deriving (Show, Typeable) instance Exception BazErrors -- sample functions foo :: (Throws FooException l) =&gt; a -&gt; EM l a foo a = return a bar :: (Throws BarErrors l) =&gt; a -&gt; EM l a bar _ = throw BarErrors baz :: (Throws BazErrors l) =&gt; a -&gt; EM l a baz a = return a -- using all at once: allAtOnce :: (Throws FooException l, Throws BarErrors l, Throws BazErrors l) =&gt; a -&gt; EM l String allAtOnce x = do _ &lt;- foo x _ &lt;- bar x _ &lt;- baz x return "success!" -- now running the code, catching the exceptions: run :: a -&gt; String run x = runEM $ allAtOnce x `catch` (\(_ :: FooException) -&gt; return "foo failed") `catch` (\BarErrors -&gt; return "bar failed") `catch` (\BazErrors -&gt; return "baz failed") -- run 3 results in "bar failed" </code></pre> <p>See also the papers <a href="http://users.dsic.upv.es/~jiborra/papers/explicitexceptions.pdf">Explicitly Typed Exceptions for Haskell</a> and <a href="http://community.haskell.org/~simonmar/papers/ext-exceptions.pdf">An Extensible Dynamically-Typed Hierarchy of Exceptions</a> for more details on using this library.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload