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? Cheers, Simon