Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import Control.Exception
import System.IO.Unsafe
match :: (a -> b) -> a -> Maybe b
match m a = unsafeDupablePerformIO $
handle (\(PatternMatchFail _) -> pure Nothing) $ do
x <- evaluate (m a)
return (Just x)
what :: Either a b -> Maybe b
what = match (\case Right x -> x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment