caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@janestcapital.com>
To: Roland Zumkeller <roland.zumkeller@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] F#
Date: Thu, 08 Mar 2007 12:54:24 -0500	[thread overview]
Message-ID: <45F04DD0.5010505@janestcapital.com> (raw)
In-Reply-To: <d02dcb040703080930g4304e049p1d8b1e700495bb6b@mail.gmail.com>

Roland Zumkeller wrote:

> Wasn't there a more or less good reason for OCaml *not* to support
> operator overloading?
>
Yes.  Ocaml has modules and functors.  IMHO, any time you thing "boy, 
it'd be really nice to use operator overloading here", you should use a 
module and a functor instead.

I have a long post on this topic comming soon, but for now:
1) Functors state up front what operators need to be provided to the 
code.  This is less of a problem with purely numeric code, but I've yet 
to see a language that allowed operator overloading and then exercised 
the restraint and kept them only on numeric types.  At which point, 
having it stated in the .mli file what operators are needed, and having 
it checked that you're actually providing them, is nice.

2) Functors allow for more flexible semantics as to what operations need 
to be provided, so operations that aren't obviously operators can be 
required as well- for example, Newton's method likes having an "equals 
within epsilon" function, or norm operation, neither of which are really 
operators.

3) Functors allow for more types- for example, if you're doing Newton's 
method on complex numbers, the type of an epsilon, or the type of a 
norm, is not a complex number, but instead just a real.  Or if you're 
doing Newton's method on vectors, the type of the derivitive is a 
matrix.  These are easy to express this with functors, hard to do with 
operator overloading.

4) Functors make it easier to swap in alternate implementations of 
various operations.  For example, doing Newton's method on vectors, you 
end up needing to calculate b/A, where A is a matrix and b a vector.  
This is easy enough to translate as solving Ax=b, you standard linear 
system.  It's nice to be able to switch out which linear system solver 
you want to use with functors, rather harder with operator overloading.

Brian


  reply	other threads:[~2007-03-08 17:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-08 14:41 Robert Fischer
2007-03-08 15:10 ` Jon Harrop
2007-03-08 17:30   ` Roland Zumkeller
2007-03-08 17:54     ` Brian Hurt [this message]
2007-03-08 19:40       ` [Caml-list] Operator overloading Jon Harrop
2007-03-08 20:44         ` Brian Hurt
2007-03-08 22:24         ` Fernando Alegre
2007-03-08 23:07       ` [Caml-list] F# skaller
  -- strict thread matches above, loose matches on Subject: below --
2007-03-08  1:13 Interactive technical computing Jon Harrop
2007-03-08  2:12 ` [Caml-list] " Erik de Castro Lopo
2007-03-08 12:41   ` [Caml-list] F# Jon Harrop
2002-06-10 14:04 Don Syme
     [not found] <BCDB2C3F59F5744EBE37C715D66E779C0481E208@red-msg-04.redmon d.corp.microsoft.com>
2002-06-09 17:49 ` Chris Hecker
2002-06-09 12:26 Don Syme
2002-06-10  6:22 ` Michael Vanier
     [not found] <BCDB2C3F59F5744EBE37C715D66E779C0481E206@red-msg-04.redmon d.corp.microsoft.com>
2002-06-09  1:30 ` Chris Hecker
2002-06-08 23:04 Don Syme
2002-06-08 15:05 Vincent Foley
2002-06-08 16:01 ` Xavier Leroy

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=45F04DD0.5010505@janestcapital.com \
    --to=bhurt@janestcapital.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=roland.zumkeller@gmail.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;
as well as URLs for NNTP newsgroup(s).