From: brogoff@speakeasy.net
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic variants and signatures
Date: Sun, 15 Jun 2003 22:21:37 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.44.0306152159450.29773-100000@grace.speakeasy.net> (raw)
In-Reply-To: <20030616101112O.garrigue@kurims.kyoto-u.ac.jp>
On Mon, 16 Jun 2003, Jacques Garrigue wrote:
[...snip...]
> > Is there some way I can write such a module type, and, after having
> > written it, use it in a functor as follows,
> >
> > module Make (Cell : CELL_TYPE) =
> > struct
> > type ('a, 'b) t = [`Newtag of 'b list | ('a, 'b) Cell.t]
> >
> > (* and some dispatch on `Newtag and #Cell.t *)
> > end
>
> This is just plain impossible. In order to dispatch on a variant
> type, you must explicitely know all its cases. If Cell.t is
> abstract,then the pattern #Cell.t is not defined. Even allowing just
> your type definition would make then implementation unsound (all
> complete variant types must known).
I thought this was probably the case, since, as you say below, polymorphic
variants (and objects) don't mix well with a functorized style of programming
and they don't really support type abstraction.
It's true that I'm trying to have my cake (type abstraction) and eat it
(dispatch on the abstract tags) too.
> This is just the same thing as with objects: you cannot build a functor
> to create a class inheriting from a class given in parameter, as long
> as you don't give an explicit class type for the parameter, indicating
> at least all the public methods.
>
> Polymorphic variant don't mix well with functors: they allow
> incremental progamming, but not type abstraction. Do you really need a
> functor here? Actually, both variants and objects alleviate a great
> part of the need for functors.
I suppose I can get by without functors. The reason I was considering
functorizing the code is that I was trying to abstract the incremental
building of a variant type (you're familiar with the example, where I
start with leaves, rows, and columns in a basic type, then add matrices and
virtual grids and ...) such that I could more easily alternate the order
of the successive additions. Right now each addition requires the last thing to
be added to textually refer to the previous thing. I was hoping to get beyond
that.
I hope that last paragraph made sense. I'm still looking for a better approach
to this. Hopefully you'll write something up in your next paper on the topic.
> Of course, if you make t concrete in CELL_TYPE, there is no problem.
Right, but in that case the functor approach is no longer that useful.
> Not very helpful,
Helpful enough. This confirmed some of my suspicions. Thanks!
-- Brian
-------------------
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
prev parent reply other threads:[~2003-06-16 5:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-15 6:01 brogoff
2003-06-16 1:11 ` Jacques Garrigue
2003-06-16 5:21 ` brogoff [this message]
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=Pine.LNX.4.44.0306152159450.29773-100000@grace.speakeasy.net \
--to=brogoff@speakeasy.net \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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