Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] "polymorphic" exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <mottl@m...>
Subject: [Caml-list] "polymorphic" exceptions?
Hello,

not long ago there was an article here about using type variables to
parameterize local modules. I just came across a class of problems
where this seems like a very nice feature: having "polymorphic"
exceptions. E.g.:

  type index

  let add ord_el (el : 'el) map =
    let module M =
      struct
        exception Found of index * 'el
      end in
    try
      (* try to add new node or raise exception if key already exists *)
      ...
    with Found (index, node) ->
      update_node index { node with el = el } map.nodes

It is really a pity that it is not allowed to write

  exception Found of index * 'el

even though the type variable is bound in "el : 'el". This seems perfectly
safe to me, because only the body of "add" can see the module and knows
what 'el is when catching the exception. Code outside cannot access the
module and therefore cannot catch the exception, which could be unsound if
'el is not known at this point.

As was mentioned in the former article, one can also use this trick to
parameterize local functor arguments using type variables that are bound
in the enclosing expression: surely also useful more often than once.

Is there any chance that this could be added to the language? This
wouldn't introduce any new concepts, but make some cases more general.

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr