Skip to content

can you use polysemy with ST-like "thread" types? #435

@MaciekFlis

Description

@MaciekFlis

I have this type from GPipe library: ContextT Handle os IO a where os is this "thread" type that limits the scope of what's inside ContextT, much like with ST monad
and I have a function runContextT :: (forall os. ContextT Handle os IO x) -> IO x
I'd like to be able to use use this with polysemy so I can mix other effects inside ContexT
currently I my effects are run in IO and then I liftIO to ContextT, but I'd like it to be a bit more streamlined (and testable).
So I wanted to make ContextT be basically the last effect on my stack to be interpreted IO, I tried wrapping this with my own type and interpreting it:

data GPipeWrapped os m a where
   GP :: (ContextT Handle os IO a) -> GPipeWrapped os m a
gp a = Polysemy.Internal.send (GP a)

and then interpreting:

runGPipeWrapped :: forall r os a. Member (Embed IO) r
                => Sem (GPipeWrapped os ': r) a
                -> Sem r a
runGPipeWrapped = interpret $ \case
  GP (x :: ContextT GLFW.Handle os IO x) ->
      embed $ runContextT GLFW.defaultHandleConfig x

I'm getting Could not deduce: os1 ~ os, so look's like I'm missing some RankN forall qualifier somewhere? I'm not even sure what I'm trying is possible in principle, any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions