[Haskell-cafe] MonadBaseControl and Freer

Lana Black lanablack at amok.cc
Thu Feb 1 21:23:49 UTC 2018


Hello,

I have a problem with implementing a MonadBaseControl instance for freer
monad (Eff from extensible-effects). Specifically, I don't really get
what the associated type StM should be.

As far as I understand, MonadBaseControl class does the following:
captures the current state. Performs the action passed to lifeBaseWith
or other wrapper functions. Returns the result wrapped in the captured
state.

Here's the instance I could come up with.

instance (MonadBase m (Eff r), Typeable m, SetMember Lift (Lift m) r) =>
MonadBaseControl m (Eff r) where
    type StM (Eff r) a = Eff r a
    liftBaseWith f = lift (f return)
    restoreM = id

It obviously doesn't work, but I currently have no idea how to fix it,
because `Eff r a' contains the state that needs to be captured and
cannot be decomposed without losing data as far as I can see.

The code can be found in this branch:
https://github.com/greydot/extensible-effects/tree/monadbasecontrol

As a side matter, I couldn't find any tests for MonadBaseControl
instances, and monad-control package itself lacks any tests whatsoever.
I'm curious whether there's a way to test instance correctness without
plugging it into working code, e.g. something using lifted-base, and
hoping for the best.


More information about the Haskell-Cafe mailing list