[Haskell-cafe] Exception handling when using STUArray

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Wed Mar 12 09:34:00 EDT 2008

On Mar 11, 2008, at 14:27 , Donn Cave wrote:
>     readLDAPMessage s = let [(_, msgID), (tag, body)] = berList s in
>         LDAPMessage (berInt msgID) (readResponse tag body)
> I go on to account for all the LDAP stuff I need in about 60 lines
> of that kind of thing, 1/3 of it devoted to declarations of the
> data types, and it isn't dense code, it's ... essentially declarative,
> in a simple, straightforward way, almost as if I copied it directly
> from the RFC.
> Is it `total'?  No way!  To get there, it seems to me I'd have to
> double the code, and significantly distract from its real sense.

You might want to think about the monadic use of Maybe/Either (or  
more generally MonadError), which abstracts away the checking and  
tracking into (>>=).  The error handler is then at the point where  
values are injected into / retrieved from the monadic exception,  
similar to catch (...).

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list