Alastair Reid wrote:

> [discussion of Dynamic library, etc deleted]
>
> [...]
>
> If Haskell supported extensible datatypes, it would be easy to define a
> hierarchy of exception values.  For example, the attached pseudocode
> creates a hierarchy like this:
>
>   IOError
>     Win32Error
>       GDIError
>         BadRegion
>         BadBrush
>     PosixError
>       ENOTDIR
>       ENAMETOOLONG
>       EINTR
>     UserError
>     AlreadyExists
>
> [...]

O'Haskell supports this feature.  See the example code below.

-- Johan

N.B. The current O'Haskell implementation, O'Hugs 0.4, doesn't allow
sub-/super-type constrained type annotations yet, which are necessary
for defining functions whose default branch matches every possible 
extension of its domain.  This feature is in the works, however.

===============================
module IO(...) where
  ...
  -- define the type &
  -- define some constructors

  data  IOError =  
      UserError      String  
    | AlreadyExists  FilePath
  

module Posix(...) where   -- Posix Stuff

  import IO(IOError)

  -- define a new hierarchy of errors &
  -- link the new hierarchy into IOError &
  -- define some Posix errors

  data  PosixError > IOError =
      ENOTDIR       FilePath
    | ENAMETOOLONG  FilePath
    | EINTR        
      ...


module Win32(...) where   -- Windows 95/98/NT stuff

  import IO(IOError)

  -- define a new hierarchy of errors &
  -- link the new hierarchy into IOError

  data  Win32Error > IOError



module Win32GDI(...) where   -- Windows graphics primitives

  import Win32(Win32Error)

  -- define a new hierarchy of errors &
  -- link the new hierarchy into IOError &
  -- define some GDI errors

  data  GDIError > Win32Error =
      BadRegion  HREGION
    | BadBrush   HBRUSH
      ...



Reply via email to