Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Eijiro Sumii <sumii@saul.cis.upenn.edu>
To: garrigue@kurims.kyoto-u.ac.jp
Cc: sumii@saul.cis.upenn.edu, caml-list@inria.fr
Subject: Re: polymorphic equality and overloading
Date: Tue, 04 Jul 2000 08:42:24 -0400	[thread overview]
Message-ID: <20000704084224R.sumii@saul.cis.upenn.edu> (raw)
In-Reply-To: <20000704160900Z.garrigue@kurims.kyoto-u.ac.jp>

> The answer is in your sentence: how do you define addition on tuples ?

Just in the same way as equality is defined: element-wise.  Such
automatically defined "polymorphic addition" may not make sense, but
neither may the automatically defined polymorphic equality.  For
example, the polymorphic equality doesn't make sense for fractions
represented as tuples of a denominator and a numerator, polynomials
represented as lists of coefficients, complex numbers represented as
tuples of a magnitude and an angle, etc.

> Or even on strings: ^ is not addition but concatenation;
> fun s1 s2 -> string_of_float (float_of_string s1 +. float_of_string s2)
> will give you a very different result.

So will "fun s1 s2 -> string_of_float (float_of_string s1 =
float_of_string s2)" too.

> The only form of overloading currently accepted in Caml is universal
> overloading, that is operations available at all types.
> Comparison is just "naturally" defined on almost anything,

As I wrote above, I'm wondering whether the "naturally defined"
polymorphic (in)equalities make more sense than the element-wise
defined polymorphic addition.

> There is some arbitrary part in this definition, but even so
> being able to compare values is useful anyway (Set and Map modules).

Again, I doubt how often polymorphic (in)equalities work---for
instance, what if one represents a finite partial function "f" from
complex numbers (in the polar representation) to booleans, define "f
(0.0, 0.0)" to be true, and define "f (0.0, pi)" to be false using the
Map module?

> I do not really see what would be the use of an underspecified
> addition on algebraic datatypes, for instance.

Neither do I, and I also don't see whether the polymorphic
(in)equalities are more useful than the "polymorphic addition".  That
was (and is) my question.

Eijiro



  reply	other threads:[~2000-07-05 21:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-29 21:10 Eijiro Sumii
2000-06-30 17:08 ` Brian Rogoff
2000-06-30 17:51   ` Eijiro Sumii
2000-07-04  7:09     ` Jacques Garrigue
2000-07-04 12:42       ` Eijiro Sumii [this message]
2000-07-05  1:11         ` Jacques Garrigue
2000-07-05  2:37           ` Eijiro Sumii
2000-07-05 21:22         ` Pierre Weis
2000-07-05 21:30           ` Eijiro Sumii
2000-07-05 22:15             ` Pierre Weis
2000-07-05 23:09               ` Eijiro Sumii
2000-07-06 17:18             ` Benjamin Werner
2000-07-05 22:40 John R Harrison

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=20000704084224R.sumii@saul.cis.upenn.edu \
    --to=sumii@saul.cis.upenn.edu \
    --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