I've created a function which is polymorphic in the Monad it needs to use, instead it depends on the typeclass instances that exists for this Monad. It looks like this:
fun <M> M.logic(...): Kind<M, String>
where M: MonadReader<M, Dependency>,
M: Effect<M> =
fx.monad() {
val dependency = ask().bind()
val response = effect { ...using dependency here... }.bind()
response
}
I'm using the MonadReader
to get a dependency, and I'm using Effect
, well, for effects. Now I assumed, that all I need is to use some Monad Transformers to get to this constellation of a Monad "at the end of the world" (i.e. in main()
). Something like ReaderT<ForIO, Dependency, Unit>
.
However, I can't seem to create a suitable M
(or any context) to call this method on. How can I call this method on an exact monad that has the necessary typeclass instances?