-
Notifications
You must be signed in to change notification settings - Fork 73
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
GetInspectorT #71
GetInspectorT #71
Conversation
Look at the following program: {-# LANGUAGE TemplateHaskell #-}
import Control.Monad
import Polysemy
import Polysemy.State
import Polysemy.Error
import Polysemy.Internal.Tactics
doCB :: IO String -> IO ()
doCB m = m >>= putStrLn
data Callback m a where
Callback :: m String -> Callback m ()
makeSem ''Callback
runCallback
:: Member (Lift IO) r
=> (forall x. Sem r x -> IO x)
-> Sem (Callback ': r) a
-> Sem r a
runCallback lower = interpretH $ \case
Callback cb -> do
cb' <- runT cb
ev <- runEvacuator <$> getEvacuatorT
sendM $ doCB $ do
v <- lower .@ runCallback $ cb'
pure $ maybe ":(" id $ ev v
getInitialStateT
main :: IO ()
main = do
void . (runM .@ runCallback)
. runState False
$ do
sendM $ putStrLn "hello world"
callback $ show <$> get @Bool
modify not
callback $ show <$> get @Bool
putStrLn "\n"
void . (runM .@ runCallback)
. runError @()
$ do
sendM $ putStrLn "hello world"
callback $ throw () which prints
|
@jkachmar this would let you do your retry thing |
I don't see any reason not to merge this. The fancier stuff in #69 can be done in some sort of TIME TO BIKESHED: What's a better name for this function: |
I might bikeshed As for EDIT: Also, do you sleep? 😆 |
+1 to |
I'm keen on neither
Something else to keep in mind is that the thing we're naming isn't pure. Its' type is more this: :: Sem (WithTactics e f m r) (forall x. f x -> Maybe x) |
Non-serious: From the docs -- The @f@ type here is existential and corresponds to "whatever
-- state the other effects want to keep track of." @f@ is always
-- a 'Functor'. Maybe something like If you prefer punny names, |
I like |
------------------------------------------------------------------------------ | ||
-- | Get a natural transformation capable of potentially inspecting values | ||
-- inside of @f@. Binding the result of 'getInspectorT' produces a function that | ||
-- can sometimes peek inside values returned by 'bindT'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the cases when it cannot inspect the values? Perhaps it'd be nice to document them?
The test suite is made for 0.3 and doesn't compile with earlier versions due to Yo now taking another argument since polysemy-research#71
The test suite is made for 0.3 and doesn't compile with earlier versions due to Yo now taking another argument since #71
Some of the ideas in #69