File: Spork.hs

package info (click to toggle)
haskell-xeno 0.6-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: haskell: 1,324; xml: 120; makefile: 3
file content (18 lines) | stat: -rw-r--r-- 426 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- | Like the spoon package, but for catching one specific exception
-- type and returning it.

module Control.Spork
    ( spork
    ) where

import Control.Exception
import System.IO.Unsafe

-- | Evaluate `a` and return left if it throws a pure exception.
spork
  :: Exception e
  => a -> Either e a
spork a =
  unsafePerformIO $
  (Right `fmap` evaluate a) `catches` [Handler (\e -> pure (Left e))]
{-# INLINEABLE spork #-}