
I've been using this lately to represent a process which can fail but still produce data: data UntilFail err a = a :+ UntilFail err a | Done | Fail err I know there's been discussion of this type before, but I don't remember what it was called and I can't find the right search terms to turn it up. Ring any bells? I have some awkward names for it, but maybe someone else thought of something more elegant. I have some ad-hoc functions for it: mapUntilFail :: (a -> Either err b) -> UntilFail err a -> UntilFail err b concatMapUntilFail :: (a -> UntilFail err b) -> UntilFail err a -> UntilFail err b -- | Like 'concatMapUntilFail', but consume a variable number of results. -- -- A more precise type would end with @Done [a]@. processUntilFail :: (a -> [a] -> (UntilFail err b, [a])) -> [a] -> UntilFail err b Maybe someone who has thought more deeply about it has come up with more elegant abstractions.