caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: OCAML <caml-list@inria.fr>
Subject: [Caml-list] "polymorphic" exceptions?
Date: Mon, 25 Jun 2001 15:29:20 +0200	[thread overview]
Message-ID: <20010625152919.A18486@miss.wu-wien.ac.at> (raw)

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


             reply	other threads:[~2001-06-25 13:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-25 13:29 Markus Mottl [this message]
2001-07-19  6:51 ` CREGUT Pierre FTRD/DTL/LAN
2001-07-19 11:37   ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010625152919.A18486@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).