[Haskell-beginners] Calculations that might fail: with arrays
elviotoccalino at gmail.com
Thu Jun 9 02:14:29 CEST 2011
Mmm... well, by looking at the type of it I can't infer what you'd do
with the returned value of the wrapped function (the action to be
should that last 'a' be a mappend'ed result of all others? or is it the
last 'a'? maybe it's meaningless?
El mié, 08-06-2011 a las 16:09 -0800, Christopher Howard escribió:
> I was wondering if there was a stock function or package in Haskell that
> allows you to map over a list, but short-circuits the mapping if any of
> the calculations fail. Say, something like this:
> -- Don't know if this is a valid signature! :)
> mapThatCanFail :: (b -> Either a b) -> [b] -> Either a [b]
> The idea being that, if any calculations fail, the function doesn't
> bother mapping the rest of the list, but just returns a Left value
> (error). Otherwise, it returns a Right value containing the new list.
> I suppose I could try to implement that myself, but it seems like the
> sort of thing that someone would have thought of already.
More information about the Beginners