<div dir="ltr"><div><div><div>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:<br><br></div>data ParsedConfig = ParsedConfig {<br></div> server :: HostName,<br></div> port :: Int<br><div><div><div>}<br><br></div><div>parseConfig = runConfigParser $ do<br></div><div> server <- readString "server"<br></div><div> port <- readInt "port"<br></div><div> return ParsedConfig{..} -- record wild card<br><br></div><div>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.<br><br></div><div>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?)<br></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 2, 2015 at 4:32 PM, Alexey Uimanov <span dir="ltr"><<a href="mailto:s9gf4ult@gmail.com" target="_blank">s9gf4ult@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi guys, here is reworked applicative-fail</div><div><br></div><a href="http://hackage.haskell.org/package/applicative-fail-1.0.0" target="_blank">http://hackage.haskell.org/package/applicative-fail-1.0.0</a><br><div><br></div><div>You can use it to e.g. parse requests in your web application, or in any other parse-like stuff.</div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>