Skip to content

Instantly share code, notes, and snippets.

@Garciat
Created May 14, 2021 11:29
Show Gist options
  • Save Garciat/ad611c97f05881becdb4a98329e734d3 to your computer and use it in GitHub Desktop.
Save Garciat/ad611c97f05881becdb4a98329e734d3 to your computer and use it in GitHub Desktop.
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