Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
{-# LANGUAGE DeriveDataTypeable #-}
module LEM where
import Control.Exception
import Data.Typeable
import System.IO.Unsafe
data Void
absurd :: Void -> a
absurd a = a `seq` error "Value of type void."
type Lem a = Either a (a -> Void)
newtype Wrap a = Wrap { unwrap :: a } deriving (Typeable, Show)
instance (Show a, Typeable a) => Exception (Wrap a)
cut :: (Show a, Typeable a) => (Lem a -> c) -> c
cut f = unsafePerformIO $ catch lie recover
where lie = return $! f $ Right $ throw . Wrap
recover = return . f . Left . unwrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment