Skip to content

Instantly share code, notes, and snippets.

@gallais
Last active August 29, 2015 14:06
Show Gist options
  • Save gallais/892e400524bef4405fde to your computer and use it in GitHub Desktop.
Save gallais/892e400524bef4405fde to your computer and use it in GitHub Desktop.
{-# 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