Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
I'm trying to migrate my code from Control.Monad.Free to polysemy; does anyone have an example that shows how to use the State effect in my own effect?
data ActivityLang m a where
SetNote' :: Text -> ActivityLang m ()
runActivityPure :: Sem (ActivityLang ': r) a -> Sem r a
runActivityPure = interpret $ \case
SetNote' s -> pure () -- TODO: modify the reader env using `s`
runFoo :: Sem (ActivityLang : State (Entry' Covered Maybe) : r) a -> Sem r _
runFoo = runState initialEntry . runActivityPure
But how would you compose the two effects so I can use the reader in SetNote'?
(Correction: State, not Reader)
End goal: "ActivityLang" describes the DSL to ultimately build (piecemeal) a Haskell record . So it is pure, except for using a State to represent intermediate states of the record (represented using barbie HKD)
@Sridhar Ratnakumar try reinterpret:
runAL :: Sem (ActivityLang : r) a -> Sem (State (Entry' Covered Maybe) : r) a
runAL = reinterpret \case
SetNote' s -> useStateWith s
That worked, and I've successfully migrated to polysemy!