[Haskell-cafe] How to handle recoverable errors in multi-step computation?

Roman Cheplyaka roma at ro-che.info
Sat Feb 6 08:58:27 UTC 2016

It sounds like you want the Validation applicative functor.
See e.g. https://ro-che.info/articles/2015-05-02-smarter-validation

On 02/06/2016 04:58 AM, Lian Hung Hon wrote:
> Dear haskellers,
> I have a multi-step computation. The steps are predefined, but users can
> choose which steps to execute (something like a recipe). Here is an
> example recipe:
> Step 1 - Get data from network (multiple HTTP calls) and put into a list
> Step 2 - Process the data (e.g. average, sum, median, etc.)
> Step 3 - Persist result to database
> Sometimes, Step 1 can fail for some of the HTTP calls. When this
> happens, Step 2 should continue as much as possible using whatever data
> that has been retrieved, but somehow indicate that an error has occurred
> and the result is partial.
> Q1: What is the idiomatic way of achieving this? Using throwError in
> Control.Monad.Except aborts the computation, which isn't what I want.
> Q2: (General software design) Furthermore, where should the error be
> logged? Logging it in both Step 1 and 2 preserves modularity for each of
> the steps, unfortunately it would result in duplicate error messages.
> What is the best practice for this?
> Regards,
> Hon
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160206/bfe98c67/attachment.sig>

More information about the Haskell-Cafe mailing list