Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: Brian Rogoff <bpr@best.com>
Cc: Tom _ <tom7ca@yahoo.com>, caml-list@inria.fr
Subject: Re: [Caml-list] classes vs modules
Date: Mon, 28 May 2001 01:13:02 +0200	[thread overview]
Message-ID: <20010528011302.A24955@miss.wu-wien.ac.at> (raw)
In-Reply-To: <Pine.BSF.4.21.0105271331380.656-100000@shell5.ba.best.com>; from bpr@best.com on Sun, May 27, 2001 at 13:54:21 -0700

On Sun, 27 May 2001, Brian Rogoff wrote:
> On Sun, 27 May 2001, Markus Mottl wrote:
> > Out of curiousity, would it be unsound to allow functions like the
> > following:
> > 
> >   let f (cmp : 'a -> 'a -> bool) =
> >     let module SomeSet =
> >       Set.Make (struct type t = 'a let compare = cmp end) in
> >     ()
> 
> You can do this now if you make a PolySet module by copying the
> "monomorphic" implementation from the stdlib, changing elt and t to 
> 'a elt and 'a t and, using that instead of Set, something like:

One could certainly do this. Still, I am not sure whether this issue
isn't slightly different here: 'a has to be bound, of course, and
parameterized types let you create such bindings, making them explicit
across interfaces. If the binding didn't exist, you could accidently
mix sets with incompatible elements.

Here, however, the type variable is indeed bound, and there is no way
that we can escape this binding (if I am not mistaken): if you happen
to use set elements like e.g. integers somewhere in this function, all
"'a"s there would unify to this type. This makes it impossible that we
can accidently mix incompatible instances of sets, because there is only
one (since explicitly bound) version of "'a".

If we don't restrict the type of "'a" in the function body by using
values of this type in specific contexts, it seems we can't do evil things
either. Note that you cannot return values from functions if the type of
these values is defined in a local module only (again, because the type
couldn't be identified outside anymore). But returning values of types
bound outside (also ones of type 'a) should be perfectly ok, n'est-ce pas?

> I thought you could never have type variables on the right hand side if
> they were'nt also on the left?

Well, the requirement is that the type variable be bound so as not to
lose track about its true identity. I am not an expert in type systems
so maybe I just don't see other problems. At least it seems to me that
a relaxation (generalization?) of the typing rules here would work
fine. In any case, the current error message is obviously misleading,
because 'a is really bound.

> Besides, currently ML type annotations are without teeth, as you are
> well aware; as a translator of Okasaki's algorithms you surely miss
> polymorphic recursion.

Sure, but as I said, I think your argument concerning mandatory type
declarations is a different issue.

Regards,
Markus Mottl

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


  reply	other threads:[~2001-05-27 23:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-27 13:31 Tom _
2001-05-27 16:14 ` Markus Mottl
2001-05-27 20:54   ` Brian Rogoff
2001-05-27 23:13     ` Markus Mottl [this message]
2001-05-27 23:52     ` Tom _
2001-05-28  4:15       ` Brian Rogoff
2001-05-28  8:34       ` Andreas Rossberg
2001-05-28  8:24   ` Andreas Rossberg

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=20010528011302.A24955@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=tom7ca@yahoo.com \
    /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