[Haskell-cafe] Are there standard idioms for lazy, pure error handling?

John Millikin jmillikin at gmail.com
Mon Nov 30 23:10:56 EST 2009


On Mon, Nov 30, 2009 at 03:02, Duncan Coutts
<duncan.coutts at googlemail.com> wrote:
> On Mon, 2009-11-30 at 06:08 +0000, Malcolm Wallace wrote:
>> However, if you really want to terminate the stream at
>> the first error, and to reflect this in the type, then I guess you can
>> define your own list type:
>>
>> data ListThenError e a = Cons a (ListThenError e a)
>>                         | Error e
>>
>> Of course this has the disadvantage that then your consumer must
>> change to use this type too.
>
> I've been using this list type quite a lot recently. It's in the 'tar'
> package for example. It comes with variants of the standard functions
> foldl, foldr, unfoldr that take into account the error possibility.
>
> At some point we should probably make a package to standardise and
> document this lazy error handling idiom.

Wow, this is perfect! I've extracted that type out into the
"failable-list" library[1], with a few added instances for common
classes (Monad, Applicative, Traversable, etc).

[1] http://hackage.haskell.org/package/failable-list


More information about the Haskell-Cafe mailing list