caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe TROESTLER <debian00@tiscali.be>
To: eijiro_sumii@anet.ne.jp
Cc: caml-list@inria.fr, sumii@saul.cis.upenn.edu
Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics
Date: Wed, 06 Apr 2005 19:00:26 +0200 (CEST)	[thread overview]
Message-ID: <20050406.190026.17170033.debian00@tiscali.be> (raw)
In-Reply-To: <20050406.111505.68543084.eijiro_sumii@anet.ne.jp>

On Wed, 06 Apr 2005, Eijiro Sumii <eijiro_sumii@anet.ne.jp> wrote:
> 

Well, I am not anywhere as much known as you are in the FP community
but let me jump in anyway! :)

> So here it goes: why don't we have polymorphic +, -, etc. while we
> have polymorphic =, <, etc.? [...] define +, -, etc. for as many
> types as possible such as integers, floating-point numbers, and tuples?

IMHO, the problem is not that much to have an handy set of polymorphic
operators than to be able to _extend_ them. See for example

http://cvs.alioth.debian.org/cgi-bin/cvsweb.cgi/shootout/bench/implicitode/implicitode.ocaml?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=shootout

for a use of [open] and [let ... and ...] at the right places for the
expressions to look "nice" (e.g. [a * b] instead of [M.( * ) a b]).
In the mathematical world, this need occurs all the time.  E.g. you
define finite fields and want +, =,... to operate on those.  You also
want to define generic algorithms with those notions, e.g. power (as
of now, functors would be used for this).  The main difficulties
currently are that (1) it is difficult to use [open] at the right
places -- I have not checked whether the "openin" camlp4 extension can
handle unary and binary operators -- and (2) mixing the operators in a
single expression is impossible -- e.g. (a * b) * matrix.  However, I
would strongly like all this to be statically type checked -- no
exceptions _please_.  In fact, provided a suitable mechanism is found,
I would like = to stop throwing exceptions.

Personally I do not mid about +., *.,... even though admittedly they
are odd at the beginning.  But if 1 + 1.2 is going to throw an
exception, this is far far worse (simple typing mistakes will now
"crash" the program!!!).

> P.S. I believe I'm not proposing anything as serious as Haskell type
> classes.

Imagine how

  val plus : [| int -> int -> int
              | float -> float -> float |] = <generic>

will look once there are 10 types.  This is going to be even worse if
equality is to be _completely_ statically checked (as I desire).  I
only know superficially type classes, but

  (=) : Eq 'a => 'a -> 'a -> bool

is much more readable than

  (=) : [| int -> int -> bool
	 | float -> float -> bool
	 | 'a list -> 'a list -> bool
	 | ...                        |]

Moreover and more importantly, they can be extended (e.g. add Num.num
to the Eq class).  Also, "subclassing" should be possible (e.g. Ordered 'a
=> Eq 'a).  We are not allowing capitalized type names; this is a good
opportunity to use them!

In summary (since the opened the Pandora box), it would be nice if a
solution would be found to this "problem" but, let's go for a general
and useful one, not an had-oc one.  :)

Regards,
ChriS

---
P.S.  Maybe GADTs provide an alternative solution for named functions
but I believe not for binary operators.


  parent reply	other threads:[~2005-04-06 17:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-06 15:15 Eijiro Sumii
2005-04-06 15:51 ` [Caml-list] " Sébastien Hinderer
2005-04-06 15:56 ` Richard Jones
2005-04-06 16:43   ` Dmitry Lomov
2005-04-06 18:59     ` Richard Jones
2005-04-06 19:19       ` Jacques Carette
2005-04-07  0:01       ` Ethan Aubin
2005-04-06 16:39 ` [Caml-list] " William Lovas
2005-04-06 16:59   ` Andreas Rossberg
2005-04-06 18:50   ` Eijiro Sumii
2005-04-06 19:33   ` Eijiro Sumii
2005-04-07  0:13     ` William Lovas
2005-04-07  1:58       ` Jacques Garrigue
2005-04-06 17:00 ` Christophe TROESTLER [this message]
2005-04-06 19:20   ` Eijiro Sumii
2005-04-07 14:00     ` Christophe TROESTLER
2005-04-06 17:23 ` Marcin 'Qrczak' Kowalczyk
2005-04-06 18:01   ` padiolea
2005-04-06 19:14     ` Eijiro Sumii
2005-04-06 20:31       ` Eijiro Sumii
2005-04-06 21:53         ` Marcin 'Qrczak' Kowalczyk
2005-04-06 22:38           ` Eijiro Sumii
2005-04-06 19:23     ` Richard Jones
2005-04-09  2:58 ` Jon Harrop
2005-04-09  3:16   ` Eijiro Sumii

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=20050406.190026.17170033.debian00@tiscali.be \
    --to=debian00@tiscali.be \
    --cc=caml-list@inria.fr \
    --cc=eijiro_sumii@anet.ne.jp \
    --cc=sumii@saul.cis.upenn.edu \
    /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).