caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ker Lutyn <ker527mail@yahoo.com>
To: caml-list@inria.fr
Subject: [Caml-list] dynamically extensible sum types
Date: Tue, 24 Dec 2002 10:37:08 -0800 (PST)	[thread overview]
Message-ID: <20021224183708.89659.qmail@web40611.mail.yahoo.com> (raw)

I need a dynamically extensible sum type.  I can think of three approaches:

(1) Use polymorphic variants: `Foo of a * b, `Bar of c * d * e, etc

(2) Use exceptions: exception Foo of a * b, exception Bar of c * d * e, etc

(3) Use thunks: (fun () -> foo a b), (fun () -> bar c d e), etc

Using exceptions seems somewhat sneaky to me.  Does it have any advantages over
polymorphic variants?  The polymorphic variants seem like they might be better
since you could actually limit the domain of certain functions... thus, one
part of your program could be constrained to a subrange of the sum type, while
other parts could be opened up fully.

Until now I have been using the thunking approach in an event-based
architecture (each event on the queue is a unit->unit thunk).  This seems to
work pretty well.  But now I'm thinking that the other approaches would allow
arbitrary filters to be applied to events; i.e., the thunk approach imposes a
"read once" discipline on elements of the sum type, and in some applications
you might want "read multiple".

I'm not asking the question solely in terms of event-based architectures,
though, and I'm interested in others experience with the different approaches
to dynamically extensible sum types, and what led you to choose one approach
over the others.  Thanks!


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2002-12-25 21:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-24 18:37 Ker Lutyn [this message]
2002-12-25 23:01 ` Alessandro Baretta

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=20021224183708.89659.qmail@web40611.mail.yahoo.com \
    --to=ker527mail@yahoo.com \
    --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).