The important bits of logState are (i) the use of the result of the computation through the return value of resume and (ii) the bit of code after the call to the resumption. The use of local state (var) isn't important here.
Sorry, I should have made clear that this is an illustrative example :P The points (i) and (ii) are what I need, in my actual use case I do more complicated things than append/cons to a list.
This is the best I've been able to do (in fused-effects, sorry xD):
{-# LANGUAGE DeriveFunctor #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE GeneralizedNewtypeDeriving #-}{-# LANGUAGE KindSignatures #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE RankNTypes #-}{-# LANGUAGE TypeOperators #-}{-# LANGUAGE UndecidableInstances #-}moduleAfterResumewhereimportControl.Algebra(Algebra(..),Has,send,type(:+:)(..))importControl.Carrier.Lift(Lift,runM,sendIO)importData.Kind(Type)importData.Type.Equality()importDebug.Trace(traceM)dataAfter(m::Type->Type)kwhereAfter::String->Afterm()after::HasAftersigm=>String->m()afters=send(Afters)newtypeAfterCma=AfterC{runAfterC::forallb.(a->mb)->mb}deriving(Functor)instanceApplicativem=>Applicative(AfterCm)wherepurea=AfterC($a)AfterCf<*>AfterCv=AfterC$\c->f$\g->v(c.g)instanceMonadm=>Monad(AfterCm)wherereturnx=AfterC($x)m>>=k=AfterC$\c->runAfterCm(\x->runAfterC(kx)c)evalAfterC::(Monadm)=>AfterCmr->mrevalAfterCm=runAfterCmreturnlift::(Monadm)=>ma->AfterCmaliftm=AfterC(m>>=)resetT::(Monadm)=>AfterCmr->AfterCmrresetT=lift.evalAfterCshiftT::Monadm=>(forallb.(a->mb)->AfterCmb)->AfterCmashiftTf=AfterC(evalAfterC.f)instance(Has(LiftIO)sigm,Algebrasigm)=>Algebra(After:+:sig)(AfterCm)wherealghdlsigctx=casesigofL(Afters)->shiftT(\k->lift$dores<-k(()<$ctx)sendIO(putStrLns)returnres)Rother->lift$alg(evalAfterC.hdl)otherctxtest::(HasAftersigm,Has(LiftIO)sigm)=>m()test=dotraceM"0"sendIO(putStrLn"a")after"a"traceM"1"sendIO(putStrLn"b")after"b"traceM"2"return()runTest::IO()runTest=dorunM.evalAfterC$test
The monad carrier is the Codensity monad, so it has delimited continuation operations which I use. But it feels like I must be doing something wrong. Can I somehow explicitly get the continuation for the rest of the computation without using a continuation type monad as the carrier?
Hi all, I've looked around this Zulip and the Polysemy repo, but I can't figure out how to write the following Koka program with Polysemy:
which results in:
The important bits of
logState
are (i) the use of the result of the computation through the return value of resume and (ii) the bit of code after the call to the resumption. The use of local state (var
) isn't important here.This sort of looks like
Writer
?: https://hackage.haskell.org/package/polysemy-1.7.1.0/docs/Polysemy-Writer.html#t:WriterSorry, I should have made clear that this is an illustrative example :P The points (i) and (ii) are what I need, in my actual use case I do more complicated things than append/cons to a list.
This is the best I've been able to do (in
fused-effects
, sorry xD):which produces:
as desired.
Is this the "right" way to do point (ii)?
The monad carrier is the
Codensity
monad, so it has delimited continuation operations which I use. But it feels like I must be doing something wrong. Can I somehow explicitly get the continuation for the rest of the computation without using a continuation type monad as the carrier?Unfortunately, due to the universal quantification of
b
inAfterC
, I can't do anything with the result really. So this doesn't solve point (i).