I'm struggling to get the right shape for the async call, in the first case I get an f a, in the second case it's a Sem that has one W too many in the Tactics part. Any pointers?
@TheMatten thanks! that's a nice tool. In my case though, the function for which I want to bundle is not a Sem, but a Stream (Of a) (Sem r) (), and I can't get it to work there (I tried MFunctor.hoist (sendBundle @Async).
Also, my impression is that calling other effects from an interpreter is a fairly integral mechanism, so shouldn't it be possible with higher-order effects? Do you know if there's a way? I tried dissecting the machinery with decomp and fiddling with the Weaving and Union stuff, but it probably takes a while to internalize this enough to be able to work with it competently.
ok, I see now that I can use lift $ send $ injBundle $ Async.Async m inside of the function. A bit verbose, but it will do.
Still interested in how to do the thing from the first post though!
FYI!
After having fortified my intuition about Polysemy, I took another stab at this and it turned out to be quite simple with a piece of code from the interpreter for Async:
well, after having worked with it intensely for a month, I would say that compared to other concepts I've used it is, on average, less complicated :slight_smile: the Tactics thing is pretty intense, sure.
as far as I could tell, using Tactics directly isn't exactly popular (searching github for the functions yields few real results), so I'd assume that it needs more feedback to evolve into something more intuitive
In liftStreamEffect, I need to return an a, while I have an f a, like in the W example. But I can't use the inspector trick, because it seems to swallow the stream's state (it produces the first element ad infinitum).
I'm trying to call
async
in aninterpretH
:I'm struggling to get the right shape for the
async
call, in the first case I get anf a
, in the second case it's aSem
that has oneW
too many in theTactics
part. Any pointers?@Torsten Schmits What's the goal of
W
?@TheMatten my use case is just bundling a few effects to shorten the
Members
list@Torsten Schmits use https://www.stackage.org/haddock/nightly-2020-03-10/polysemy-1.3.0.0/Polysemy-Bundle.html then
@TheMatten thanks! that's a nice tool. In my case though, the function for which I want to bundle is not a
Sem
, but aStream (Of a) (Sem r) ()
, and I can't get it to work there (I triedMFunctor.hoist (sendBundle @Async)
.Also, my impression is that calling other effects from an interpreter is a fairly integral mechanism, so shouldn't it be possible with higher-order effects? Do you know if there's a way? I tried dissecting the machinery with
decomp
and fiddling with theWeaving
andUnion
stuff, but it probably takes a while to internalize this enough to be able to work with it competently.ok, I see now that I can use
lift $ send $ injBundle $ Async.Async m
inside of the function. A bit verbose, but it will do.Still interested in how to do the thing from the first post though!
also I want to use helpers like
sequenceConcurrently
, I'll try to find a way to bundle thoseoh whoops, I can just use
lift . sendBundle
:big_smile:so I'm trying my best but I can't get the bundle to work with expressions like
i.e. if there are higher order effects, again (
Resource
here).real code:
saying
Expected type: Sem (Resource : r) o, Actual type: Sem r o
on thefinally
expressionok, that was easily solved with
raise
:slight_smile:this does the trick:
bundle async sem
!final version:
pretty verbose. It would be really nice to hide this in an actual effect interpreter.
FYI!
After having fortified my intuition about Polysemy, I took another stab at this and it turned out to be quite simple with a piece of code from the interpreter for
Async
:sweet mother of mary that's beginning to look like ghcjs code
what have i unleashed upon the world
@Sandy Maguire I'm open to suggestions :slight_smile:
sorry, let me rephrase that
"why is polysemy so complicated that that stuff is necessary?"
your code is fine!
my code is not :(
well, after having worked with it intensely for a month, I would say that compared to other concepts I've used it is, on average, less complicated :slight_smile: the Tactics thing is pretty intense, sure.
as far as I could tell, using Tactics directly isn't exactly popular (searching github for the functions yields few real results), so I'd assume that it needs more feedback to evolve into something more intuitive
and almost all results just use a simple
m a
from the interpreter effect, not others, and no transformers.I have now reimplemented the stream merging effect I posted earlier, and I'm hitting another wall:
In
liftStreamEffect
, I need to return ana
, while I have anf a
, like in theW
example. But I can't use the inspector trick, because it seems to swallow the stream's state (it produces the first element ad infinitum).would it be possible to implement a constructor for
Tactics
that absorbs anf
back into the monad?finally!! My mistake was to put some of the logic in the interpreter. I just had to prepare the producer Sems in the program:
Kinda obvious in hindsight, but I've learned a lot :grinning_face_with_smiling_eyes: