Nicolas Pouillard wrote:
> Excerpts from Heinrich Apfelmus's message of Tue Dec 01 11:29:24 +0100 2009:
>> I propose to (trivially) generalize this type to "list with an end"
>>>> data ListEnd a b = Cons a (ListEnd a b)
>> | End b
>>>> because it may have other uses than just lazy error handling. For
>> mnemonic value, we could call it a "train":
>>>> data Train a b = Wagon a (Train a b)
>> | Loco b
>>>> [...]
>> This proposition looks quite nice and gently subsume the ListThenError
> type.
>> type ListThenError e a = Train a (Maybe e)
>> Anyone to put this on Hackage?
I rather like it too. The mnemonic version sounds a lot nicer than
"ListEnd", though I'd probably call the constructors Cabin and Caboose.
The nice thing about the generalization is that even though (Train a b)
is very similar to ([a],b) it's not exactly isomorphic. There are
differences in the strictness of generating them and I've often wanted
something like Train.
Wherever this ends up, it'd be pretty easy to do train-fusion in order
to reduce the cost over using lists. If noone else wants to take it, I
could probably find a few tuits to get it done. Though it looks like
John Millikin already has failable-list up on Hackage, which differs
only in also having a Nil to end with (which interferes with certain
fusions, but not the major ones).
--
Live well,
~wren