Created
December 26, 2025 09:28
-
-
Save tomjaguarpaw/bf510ccde477e8a572e82ab2ce5c8b0b to your computer and use it in GitHub Desktop.
Bluefin demand analyser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE GHC2021 #-} | |
| import Bluefin.Eff | |
| import Bluefin.Exception | |
| import Bluefin.IO | |
| import Control.Exception hiding (Exception, catch, throw) | |
| {-# NOINLINE f #-} | |
| f :: Int -> Int -> IO Int | |
| f x y | |
| | x > 0 = throwIO (userError "What") | |
| | y > 0 = return 1 | |
| | otherwise = return 2 | |
| {-# NOINLINE fEffIO #-} | |
| fEffIO :: (e :> es) => IOE e -> Int -> Int -> Eff es Int | |
| fEffIO io x y | |
| | x > 0 = effIO io (throwIO (userError "What")) | |
| | y > 0 = return 1 | |
| | otherwise = return 2 | |
| {-# NOINLINE fEffException #-} | |
| fEffException :: (e :> es) => Exception String e -> Int -> Int -> Eff es Int | |
| fEffException ex x y | |
| | x > 0 = throw ex "What" | |
| | y > 0 = return 1 | |
| | otherwise = return 2 | |
| -- ghci> mainIO | |
| -- *** Exception: user error (What) | |
| mainIO = f 2 undefined >>= print | |
| -- ghci> mainEffIO | |
| -- *** Exception: user error (What) | |
| mainEffIO = runEff_ (\io -> fEffIO io 2 undefined) >>= print | |
| -- ghci> mainEffException | |
| -- *** Exception: user error (What) | |
| mainEffException = | |
| runEff_ | |
| ( \io -> | |
| catch | |
| (\ex -> fEffException ex 2 undefined) | |
| (effIO io . throwIO . userError) | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment