[Haskell-cafe] ANN: applicative-fail-1.0.0

Joey Adams joeyadams3.14159 at gmail.com
Mon May 4 16:52:33 UTC 2015


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 at 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150504/b8f48d6c/attachment.html>


More information about the Haskell-Cafe mailing list