Skip to content

Instantly share code, notes, and snippets.

@gallais
Last active Aug 29, 2015
Embed
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