Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a stateless version of MockT #7

Open
pepeiborra opened this issue Apr 12, 2019 · 1 comment
Open

Provide a stateless version of MockT #7

pepeiborra opened this issue Apr 12, 2019 · 1 comment

Comments

@pepeiborra
Copy link

pepeiborra commented Apr 12, 2019

As described here the class of monads for which StM m a ~ a holds enjoy better compositionality properties than the ones that do not.

This property does not currently hold for MockT, as StM (MockT f) a ~ (a, [WithResult f]). This is a consequence of building MockT f on top of StateT [WithResult f] m, and it limits the applicability of MockT in monad stacks which require a stateless MonadTransControl instance. This is not an academic concern - it happens to be quite common these days.

To address this,MockT can be defined on top of ReaderT (IORef [WithResult f]) m, which possesses a MonadIO instance as long given MonadIO m. Or more generally using MutVar from the primitive package.

Since this incurs in additional constraints for the base monad, it's not a backwards compatible change. An alternative is to add a Control.Monad.Mock.Stateless module with a one-for-one replacement for MockT.

@pepeiborra
Copy link
Author

I'm happy to work on this if the contribution would be considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant