From custom Monad to Polysemy
Previously we have studied a custom Monad
and how to refactor it to make it easier to work with.
For reminder, it was this one:
And it was used as a basis for:
At some point, we would like to integrate it with a broader Polysemy-based codebase.
A first move to make would be to replace each reader by Polysemy Reader
s effects:
type MyAppMonadEffects =
'[ Reader SmtpConfig,
Reader S3Config,
Reader RedisParams
]
Then, to avoid any change in the codebase, we have to drop in MyAppMonad
with a fixed EffectsRow
:
type MyAppMonad m = m ~ Sem MyAppMonadEffects
And then our getters:
getSmtpConfig = ask
getS3Config = ask
getRedisParams = ask
It's not ideal as effects being fixed dealing with this code (calling/being called by)
would require raise
each time effects differ.
But that's a first step, then we can progressively substitute consumers with
Sem r
/Members
and create individual effects/interpreters.