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

Can the Tactical Functor be Traversable? #367

Open
IamfromSpace opened this issue Jul 26, 2020 · 0 comments
Open

Can the Tactical Functor be Traversable? #367

IamfromSpace opened this issue Jul 26, 2020 · 0 comments

Comments

@IamfromSpace
Copy link

I've been playing around with Polysemy recently, and have had some reasonable success with first order interpreters--they really deliver on "write the code the way you wish you could."

I recently tried creating some higher-order interpreters and found it (maybe unsurprisingly) much more challenging. Should these even be really expected within application code, or are these really reserved for things like Resource and Error?

I've started to get my head around the types, but I seems like certain cases with additional actions from constraints are especially challenging. runT and bindT work together to allow chaining the functor through their computations, but if you try to use an effect not in a parameter, the arbitrary Functor requirement gets a bit awkward. In certain cases it seems like you must inspect the state or you end up stuck.

My thought was, that if the Functor was instead Traversable, you could use that to "upgrade" the action in the same way that you use bindT to upgrade the action in the parameter. As an example:

higher = (Member Other r) => Sem (Higher ': r) a -> Sem r a
higher = interpretH \case
  Higher paramA paramB -> do
    paramA' <- runT paramA
    a <- paramA'
    paramB' <- bindT paramB'
    b <- paramB'
    traverse other b

This essentially lets us perform the other action inside the (now Traversable) Functor, but then flip the contexts to end up with the correct type. Ultimately, we're saved from otherwise having to inspect the state.

Is Traversable a reasonable constraint to get the ergonomics here? What actual Functors are used under the hood? I was assuming that while Maybe is used for inspecting, it's not actually ever used as f.

Also, if I'm simply thinking about this problem incorrectly, I'd much appreciate a push in the correct direction. Thanks!

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