On 28-Sep-1999, Alastair Reid <[EMAIL PROTECTED]> wrote:
> 
> > > > (b) allow throwing and catching of dynamically typed values,
> > > >     e.g. using an interface like the Hugs/ghc Dynamic library
> 
> [discussion of Dynamic library, etc deleted]
> 
> [The following is a bit of a straw-man: it doesn't quite work but
> may have good parts which can be used in other designs.]
> 
> (part of) Another approach is to extend Haskell with extensible
> datatypes as is done in ML.
...
> If Haskell supported extensible datatypes, it would be easy to define a
> hierarchy of exception values.
...
> Disadvantages of this approach include:
> 
> o Most Haskell features can be described as "just syntactic sugar"
>   - it's hard to do this here.
> 
> o It's hard to write total functions over extensible datatypes (eg
>   try writing a Show function for the attached definition of IOError).
> 
> o This is the only compelling use for extensible datatypes - wouldn't
>   it be better to support exception handling more directly?

Another disadvantage is that with this approach you miss out on
multiple inheritance.  Your example categorization

>   IOError
>     Win32Error
>       GDIError
>         BadRegion
>         BadBrush
>     PosixError
>       ENOTDIR
>       ENAMETOOLONG
>       EINTR
>     UserError
>     AlreadyExists

categorizes errors according to the subsystem that produced them
(Win32, Posix), but often you want to categorize errors differently,
and some errors may fall into multiple categories.

Note that using `Dynamic', you could easily implement the same kind of
single-inheritance hierarchical categorization as in your post,
using nested Dynamic values rather than nested extensible types.
But with the appropriate language extension for dynamic type class casts,
Dynamic could also be used for single- or multiple-inheritance hierarchies
based on type classes rather than nesting, whereas I don't see any way
to extend the extensible type approach to support multiple-inheritance
hierarchies.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.



Reply via email to