Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImplicitParams don't work well #32

Open
tomjaguarpaw opened this issue Dec 7, 2024 · 0 comments
Open

ImplicitParams don't work well #32

tomjaguarpaw opened this issue Dec 7, 2024 · 0 comments

Comments

@tomjaguarpaw
Copy link
Owner

We might like to pass Bluefin handles as ImplicitParams, but it doesn't work well, because of the same incoherent instance type inference issues as in #21.

Here's a demonstration of the best I have been able to achieve so far:

-- welltypedwitch raised the intriguing possibility of using
-- ImplicitParams to avoid having to pass effect handles explicitly.
-- Unfortunately I've been snagged on two issues:
--
-- 1. It doesn't seem possible to bind an implicit parameter in a
-- lambda. (See
-- https://discourse.haskell.org/t/why-cant-an-implicitparam-be-bound-by-a-lambda/8936/2)
--
-- 2. Type inference gets stuck, because of the difficulty resolving
-- incoherent instances, the same as in
--
-- <https://github.com/tomjaguarpaw/bluefin/issues/21>
-- We might want to resolve 1 by putting the ImplicitParam as an
-- argument to the handler.
evalStateI ::
-- | Initial state
s ->
-- | Stateful computation
(forall st. (?st :: State s st) => Eff (st :& es) a) ->
-- | Result
Eff es a
evalStateI s f = evalState s (\x -> let ?st = x in f)
runEffI :: (forall es. (?io :: IOE es) => Eff es r) -> IO r
runEffI f = runEff (\io -> let ?io = io in pushFirst f)
countExampleImpl ::
forall e e1 es.
(?st :: State Int e1, e1 :> es) =>
(?io :: IOE e, e :> es) =>
Eff es ()
countExampleImpl = do
withJump $ \break -> forever $ do
n <- getI
when (n >= 10) (jumpTo break)
effIOI (print n)
modifyI (+ 1)
countExampleI :: IO ()
countExampleI = runEffI $ do
evalStateI @Int 0 $ do
countExampleImpl
-- When we try to use an effect bound in a local handler we get stuck.
-- We have to annotate the type.
countExampleI2 :: IO ()
countExampleI2 = runEffI $ do
evalStateI @Int 0 $ do
withJump $ \break -> forever $ do
_ :: State Int st <- pure ?st
n <- getI @st
when (n >= 10) (jumpTo break)
effIOI (print n)
modifyI @st (+ 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant