Rebinding exception declarations

From: Manuel Fahndrich (maf@microsoft.com)
Date: Wed Oct 13 1999 - 18:59:50 MET DST


From: Manuel Fahndrich <maf@microsoft.com>
To: "'caml-list@inria.fr'" <caml-list@inria.fr>
Subject: Rebinding exception declarations
Date: Wed, 13 Oct 1999 09:59:50 -0700

While we are at wishing for new features in OCaml, let me add a minor
feature to the list:

Rebinding of exception declarations.

Currently, in OCAML I cannot do the following:

module A =
  struct
     exception E
  end

module B =
   struct
       exception E = exception A.E
   end

In order to have an exception declaration in a module, it must syntactically
appear there. That prevents me from repackaging my modules in a different
way for the programmer interface. The only way around it is currently to
define a brand new exception and wrap all interface functions with a handler
that translates A.E into B.E.

One argument against providing such exception rebinding is that it
introduces aliasing between exception constructors. However, OCAML already
has that problem now through functors. Consider:

module type Argsig =
  sig
      module X : sig exception E end
      module Y : sig exception E end
  end

module F = functor(Arg : Argsig) ->
  struct

     try ...
     with
        Arg.X.E -> ...
     | Arg.Y.E -> ...

  end

module A =
  struct
     exception E
  end

module Z = F(struct module X = A module Y = A end)

Within Z, exceptions Arg.X.E and Arg.Y.E are aliased.

-Manuel

P.S. Exception rebinding is standard in SML.



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:27 MET