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)