[Haskell-cafe] Exception handling when using STUArray

Henning Thielemann lemming at henning-thielemann.de
Thu Mar 13 02:35:19 EDT 2008


On Wed, 12 Mar 2008, Donn Cave wrote:

> On Mar 12, 2008, at 2:10 PM, Henning Thielemann wrote:
>
>> On Wed, 12 Mar 2008, Donn Cave wrote:
>> 
>>> On Mar 12, 2008, at 12:32 PM, Brandon S. Allbery KF8NH wrote:
>>> 
>>>> On Mar 12, 2008, at 14:17 , Donn Cave wrote:
>>>>> Sure.  It isn't a lot of code, so I subjected it to Either-ization
>>>>> as an experiment, and I did indeed take the monad procedural route.
>>>> Monad != procedural, unless you insist on do notation.  Think of it as 
>>>> composition (it may be easier to use (=<<) which "points the same 
>>>> direction" as (.)).
>>> 
>>> Yes, I insist on do notation, because it provides a convenient
>>> binding form that works with what I'm doing - the original functional
>>> variation wasn't so suited to composition either, and used `let'.
>>> 
>>> But I see that as only syntactic - equally procedural, either way.
>>> Expressions are evaluated in a fixed order,
>> 
>> Do notation only looks like there are statements that are processed from 
>> the beginning to the end. But that's not true, it's still purely lazy and 
>> expressions are evaluated in the order that is forced by data dependencies.
>
>
> Let me put it this way:  if I write
>
>   do
>       (i, s') <- decodeInt s
>       (v, _) <- decodeInt s'
>       return (i, v)
>
> ... instead of, to just avoid the monad stuff
>
>  case (decodeInt s) of
>      Left e -> Left e
>      Right (i, s') -> case (decodeInt s') of
>         Left e -> Left e
>         Right (v, _) -> Right (i, v)

Since the decision between Left and Right requires all parts to be 
evaluated, it's Either that might too strict for your application. What 
about a writer monad, where exceptions, or better say warnings, are 
written to the writer stream?


More information about the Haskell-Cafe mailing list