ANN: applicative-fail-1.0.0
Hi guys, here is reworked applicative-fail http://hackage.haskell.org/package/applicative-fail-1.0.0 You can use it to e.g. parse requests in your web application, or in any other parse-like stuff.
On 02/05/15 23:32, Alexey Uimanov wrote:
Hi guys, here is reworked applicative-fail
http://hackage.haskell.org/package/applicative-fail-1.0.0
You can use it to e.g. parse requests in your web application, or in any other parse-like stuff.
Incidentally, I just published an article on this very subject: https://ro-che.info/articles/2015-05-02-smarter-validation
I wanted something like this in an application I wrote a couple years ago. Namely, to be able to display all errors in a config file rather than just the first. What I settled on was a monad, but if an error occurred parsing an element, the value would go into the structure undefined, and at the end of running the parser, it would check for errors before returning the structure. Something like this: data ParsedConfig = ParsedConfig { server :: HostName, port :: Int } parseConfig = runConfigParser $ do server <- readString "server" port <- readInt "port" return ParsedConfig{..} -- record wild card If the "server" attribute is not available in the input, readString "server" will return an error value, but it will return. Thus, when the ParsedConfig is constructed, it will contain holes if there are any errors. But errors are logged separately, and will be reported before the ParsedConfig is used in the application. This isn't as semantically nice as the applicative approach (suppose you try to do conditional logic on an attribute, but it's an error value), but it's convenient because you can use RecordWildCards to gather up the attributes without repeating their names. I suppose you could still do this and use ApplicativeDo, but it's not available yet (or is it?) On Sat, May 2, 2015 at 4:32 PM, Alexey Uimanov <s9gf4ult@gmail.com> wrote:
Hi guys, here is reworked applicative-fail
http://hackage.haskell.org/package/applicative-fail-1.0.0
You can use it to e.g. parse requests in your web application, or in any other parse-like stuff.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Joey Adams <joeyadams3.14159@gmail.com> writes: snip
This isn't as semantically nice as the applicative approach (suppose you try to do conditional logic on an attribute, but it's an error value), but it's convenient because you can use RecordWildCards to gather up the attributes without repeating their names. I suppose you could still do this and use ApplicativeDo, but it's not available yet (or is it?)
It's not available yet but progress is being made... [1] Cheers, - Ben [1] https://phabricator.haskell.org/D729
participants (4)
-
Alexey Uimanov -
Ben Gamari -
Joey Adams -
Roman Cheplyaka