It needs to read from input of Maybe (HashMap FieldName Text), then it makes a web API call to work out how to convert this into Maybe [Text], and provide this as input for the next step. This I can do, but the tricky bit is that the web API call also gives me a Header, which I also want to make available for a downstream step. Can anyone give me any pointers for how to do this?
I think reinterpretH will do the job here.
If you don't actually need the local operation of Reader you can entirely avoid the Tactical stuff that's inherent in reinterpretH by using Input instead of Reader and reinterpret instead of reinterpretH
I played around with this a bit to see how it would look.
What's peoples opinion on whether this actually brings any benefit (i.e. some functions that use these classes? - I want to be able to...
I can do that, and use runInputConst to effectively make Input a Reader. But what if I try the same with Writer, changing it to Output? Is there a runOutputConst equivalent? It might look like this:
runOutputOnce::(o->Semr())->Sem(Outputo': r) a -> Sem r a
There's runOutputSem, which has that type signature, but it runs for every value, and I only want it to run once.
I'm trying to run two interpreters in one function, with a type like this:
It needs to read from input of
Maybe (HashMap FieldName Text)
, then it makes a web API call to work out how to convert this intoMaybe [Text]
, and provide this as input for the next step. This I can do, but the tricky bit is that the web API call also gives me aHeader
, which I also want to make available for a downstream step. Can anyone give me any pointers for how to do this?Isn't it that you actually want
Input (Maybe [Text], Header)
?No, because I will have a stream of [Text], but only one unchanging Header, so it seems wasteful to stream the Header with the [Text].
Also, they are consumed at different points in the program.
I see - then it may be more convenient to have
Reader
on top and do something like:thanks, I'll give that a go
seems to have worked -- compiled at least!
Another question... is there an easy way to do this:
It feels a lot like
fmap
(orcontramap
), except of course it isn't changing thea
type.I think
reinterpretH
will do the job here.If you don't actually need the
local
operation ofReader
you can entirely avoid theTactical
stuff that's inherent inreinterpretH
by usingInput
instead ofReader
andreinterpret
instead ofreinterpretH
we had some discussion/progress on this issue here but it went nowhere pretty much
Oh, interesting thought! I'm yet to successfully use any of the
Tactical
stuff, so avoiding it for now would be nice.something like this?
Yes, exactly. Thanks :)
/me changes all
Reader
s toInput
sI can do that, and use
runInputConst
to effectively makeInput
aReader
. But what if I try the same withWriter
, changing it toOutput
? Is there arunOutputConst
equivalent? It might look like this:There's
runOutputSem
, which has that type signature, but it runs for every value, and I only want it to run once.Or maybe I'm misunderstanding how this works. If my program only calls
output
once thenrunOutputSem
will only have one value to act on.I don't understand what you mean by
runOutputConst
:/or rather I don't understand what you want
runOutputConst
to doif your program calls
output
oncerunOutputSem
will only "execute" once, but what if it callsoutput
more than once?Yeah, I concluded that it didn't actually make sense, and what I wanted was
runOutputSem
.