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

MonadGen class to make working with transformers easier #99

Merged
merged 1 commit into from
Jul 16, 2017

Conversation

jacobstanley
Copy link
Member

This renames Gen to GenT and introduces the MonadGen class.

The MonadGen class has instances for a number of transformers, including ReaderT and StateT. This means that it's now possible to use these transformers on the outside of a Gen, as such I think it will be much more common to have a pure Gen, so I've renamed the transformer variant to GenT and changed forAll to expect a pure Gen. Folks can use forAllT if they need effects in their generators.

I'm super happy with how this worked out, I think writing generators will be a lot cleaner now.


genWellTypedExpr' :: Type -> Gen (Reader (Map Type [Expr])) Expr
genWellTypedExpr' :: Type -> ReaderT (Map Type [Expr]) Gen Expr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 more intuitive

hoist (generalize . flip runReaderT mempty) (genWellTypedExpr' want)
genWellTypedExpr :: Type -> Gen Expr
genWellTypedExpr =
flip runReaderT mempty . genWellTypedExpr'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 💯

@jacobstanley jacobstanley merged commit d12b3e8 into master Jul 16, 2017
@jacobstanley jacobstanley deleted the topic/monad-gen branch July 16, 2017 00:58
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 this pull request may close these issues.

None yet

2 participants