[Haskell-cafe] Exception handling when using STUArray

Xiao-Yong Jin xj2106 at columbia.edu
Sat Mar 8 14:19:01 EST 2008


"Denis Bueno" <dbueno at gmail.com> writes:

> On Sat, Mar 8, 2008 at 9:54 AM, Xiao-Yong Jin <xj2106 at columbia.edu> wrote:
>>  > ArrayException?  If it is out-of-bounds reading or writing, surely
>>  > that indicates a bug in your program that you'd rather fix than catch
>>  > the exception, no?
>>
>>  In my case, because I choose a index of the array according
>>  to certain value in the array, if there is NaN or Infinity
>>  in the array, the code breaks.  So I guess, to fix the code,
>>  I would probably use isNaN/isInfinite and throw an exception
>>  when that happens.
>
> I see. In that case, you should check out the ErrorT monad transformer
> (http://haskell.org/ghc/docs/latest/html/libraries/mtl/Control-Monad-Error.html#t%3AErrorT);
> it lets you throw an error conveniently using Either.  It may or may
> not fit your needs, but at least it's worth knowing about.
>
> And in case you don't understand monad transformers: if you understand
> the State monad, the following post is a fairly nice, minimal
> explanation of monad transformers:
> http://sigfpe.blogspot.com/2006/05/grok-haskell-monad-transformers.html

Thanks.  I do need to learn some monad transformers.  And
this post is indeed very helpful.

Xiao-Yong
-- 
    c/*    __o/*
    <\     * (__
    */\      <


More information about the Haskell-Cafe mailing list