-
Notifications
You must be signed in to change notification settings - Fork 42
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
Class for things that can be parsed by Scalpel #78
Comments
For something analogous to This sounds useful to me, if you are interested in implementing this feel free to fire up a PR. |
Yes that is basically what I was thinking. After thinking about it some more there is a key difference between Aeson and Scalpel that makes this change in primitives hard: In Aeson a String parsing libraries are more or less stuck with the The advantage of the former approach is that it is significantly more powerful and allows you to basically build everything on top of polymorphic primitives like The advantage of the latter is that because of it's reduced power you can potentially implement optimizations not otherwise possible, and allow for things like printing out the structure of the parser itself (e.g. BNF form). So with that said I think a class would be nice either way, but This would IMO be a very nice and intuitive interface. |
One potential interface could be something like this:
|
I might be misunderstanding For example: class Scrapable str a where
scraper :: Scraper str a
extract :: (Scrapable str a, StringLike str) => Selector -> Scraper str a
extract selector = chroot selector scraper
extracts :: (Scrapable str a, StringLike str) => Selector -> Scraper str a
extracts selector = chroots selector scraper Internally scalpel basically uses an interface like the one you propose, the context is just implicitly passed via a Monad in the public API. Seems like you could get something similar by partially applying the existing scraping functions and passing around a Right now, I think the parsing will probably be redone for each application, but I think you could probably restructure the internals such that the parsing is only performed once. |
That is essentially true. However what makes this benefit so substantial in Currently adding functions like the above to scalpel would not allow any existing functions to be removed, as they do not supersede any existing functions. So while they are nice convenience functions, they don't really simplify the interface or give any composeable benefits.
To allow for both possible APIs to be as clean and performant as possible, one option could be combining the |
This would be very useful for things like interacting with Servant. I also like the way Aeson uses this for things like polymorphic
.:
, so that could be worth looking into.See this for the current class we are using for this purpose and this for the way we are integrating it with Servant.
The text was updated successfully, but these errors were encountered: