[Haskell] sugar for extensible types (was: class associated types, via GADTs.)

Simon Marlow simonmar at microsoft.com
Wed Feb 16 07:38:45 EST 2005

On 16 February 2005 08:08, Ralf Laemmel wrote:

> Assoc types and GADTs are great but
> I am still too fond of encoding extensible datatypes with (open)
> classes. 
> I contributed to some related discussion at comp.compilers a while
> ago [1]. The Haskell code samples are worth sharing (because they are
> sooooo simple): 
> http://homepages.cwi.nl/~ralf/OOHaskell/src/interpreter/extensible.hs
> (Note: *no* OOHaskell idioms used.)

I wish we'd done exceptions like this.  An extensible exception type is
entirely possible, and using it is not hard either - see the attached
file implemented in terms of the existing Control.Exception.  For

test = do
  x `catch` (\(IOException e)    -> print e)
    `catch` (\(ArithException e) -> print e)

and I make a new type into an exception like this:

 data T = ... deriving (Typeable, Show)
 instance Exception T

this can replace DynExceptions and the strange catchJust/tryJust stuff
in Control.Exception.  Perhaps we can figure out a reasonable migration
path that wouldn't break too much code in one go?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: exceptions.hs
Type: application/octet-stream
Size: 1083 bytes
Desc: exceptions.hs
Url : http://www.haskell.org//pipermail/haskell/attachments/20050216/d5d9669b/exceptions.obj

More information about the Haskell mailing list