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

John Meacham john at repetae.net
Thu Mar 3 22:53:12 EST 2005


On Wed, Feb 16, 2005 at 12:38:45PM -0000, Simon Marlow wrote:
> 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/nonextensible.hs
> > 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
> example:
> 
> 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?

This would be great. 

How about including this interface in a new module, perhaps
Data.ExtensibleExceptions (or something shorter?) 

then new code can use this better interface and eventually the old
interface can be depreciated. 

        John


-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell mailing list