caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: William Lovas <wlovas@stwing.upenn.edu>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Understanding why Ocaml doesn't support operator overloading.
Date: Sat, 30 Nov 2002 16:41:39 -0500	[thread overview]
Message-ID: <20021130214138.GA19662@force.stwing.upenn.edu> (raw)
In-Reply-To: <B7BFB77B-03F6-11D7-89AB-000393AE4242@mit.edu>

On Fri, Nov 29, 2002 at 07:00:21PM -0500, Mike Lin wrote:
> If this is really a problem then what gets generated when you write any 
> polymorphic function at all?

I think the whole idea behind polymorphic functions is that they don't
*care* about the type that 'a is instantiated as -- generic code that works
for all instantiations can be generated.  This is only really useful for
parametrized types, like 'a list, which is why it's called parametric
polymorphism.  As an exercise, try to write a useful function that operates
on just 'a's -- you'll find it a challenge :)  (in fact, i think there's a
theorem in one of Philip Wadler's papers that says the *only* function of
type 'a -> 'a in a purely functional language is the identity function).

> The proposal is to allow constrained 
> polymorphism; the polymorphism that is already in OCaml seems to 
> supersede this with regard to the above objection.

Overloading is also known as ad-hoc polymorphism, which as i understand it
basically means "rule-based" -- you can't generate generic code, but you
can generate all possibilites and pick the right one based on some set of
rules.

Just because "constrained polymorphism" seems less powerful than fully
parametric polymorphism doesn't mean it's just as tractable.  The analogy
that immediately came to mind for me comes from theory of computation -- a
subset of a regular language is not necessarily regular, even though it's
smaller.

> I wonder if the unification algorithm can be generalized to intersect 
> sets of allowable types instead of unifying "for all" type variables. 
> It doesn't seem too ludicrous in principle but I could easily have 
> missed some nasty corner case.

The type inference algorithm simply assigns type variables to expressions,
generates a set of constraints based on how those expressions are put
together, and then `unifies' those constraints to make sure that they don't
lead to any contradictory equalities, like `int = float'.  Trying to
generalize this would mean changing the `=' relation to something more
interesting, like maybe subset containment or something.  Clearly, this
would not be a trivial undertaking..

There has been research into "intersection types", but i don't know if they
have anything to do with your proposal... maybe someone else can shed some
light?

cheers,
William
-------------------
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


  parent reply	other threads:[~2002-11-30 21:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-28 21:02 Jørgen Hermanrud Fjeld
2002-11-28 21:27 ` Jørgen Hermanrud Fjeld
2002-11-29 15:26 ` Xavier Leroy
2002-11-29 15:42   ` Christophe Raffalli
2002-11-29 16:52   ` Nicolas Cannasse
2002-11-29 17:26     ` Michal Moskal
2002-11-30  0:00       ` Mike Lin
2002-11-30 10:24         ` Michal Moskal
2002-11-30 23:06           ` Mike Lin
2002-11-30 21:41         ` William Lovas [this message]
2002-12-01 17:30           ` Pierre Weis
2002-12-01 23:41             ` William Lovas
2002-12-02  9:52               ` Remi VANICAT
2002-11-30 21:47         ` Pierre Weis
2002-12-01  7:40           ` Christophe Raffalli
2002-11-30 21:36       ` Pierre Weis
2002-11-30 21:33     ` Pierre Weis

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=20021130214138.GA19662@force.stwing.upenn.edu \
    --to=wlovas@stwing.upenn.edu \
    --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).