Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Rebinding exception declarations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-10-14 (12:59)
From: Manuel Fahndrich <maf@m...>
Subject: Rebinding exception declarations

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 =
     exception E

module B =
       exception E = exception A.E

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 =
      module X : sig exception E end
      module Y : sig exception E end

module F = functor(Arg : Argsig) ->

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


module A =
     exception E

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

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


P.S. Exception rebinding is standard in SML.