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

Update docs to explain the hoist lift trick #31

Closed
Gabriella439 opened this issue Jul 31, 2014 · 1 comment
Closed

Update docs to explain the hoist lift trick #31

Gabriella439 opened this issue Jul 31, 2014 · 1 comment

Comments

@Gabriella439
Copy link
Owner

Writing intermediate transformations or lenses is cumbersome because of the need to do explicit state-passing. Normally, you'd want to simplify this using StateT, however the problem is that you don't get a type suitable for Parser. The type you want is:

StateT (Producer a m x) (Producer b m) r

... but that doesn't unify with Parser, so you can't embed Parsers within such a StateT block.

However, the solution is simple: you can wrap any Parser in hoist lift and then it will have the correct type:

parser :: StateT (Producer a m x) m r

hoist lift parser :: StateT (Producer a m x) (Producer b m) r

Then you can write transformations/lenses using StateT to manage all state-passing and still embed parsers within those blocks.

This ticket is to remind myself to update the documentation to explain this trick and to update the source code to use this trick, too.

@bgamari
Copy link
Contributor

bgamari commented Apr 3, 2016

I find that you end up encountering this pretty often in practice. It would be great if the documentation were better here.

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

No branches or pull requests

2 participants