Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Why are arithmetic functions not polymorph?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-05-23 (18:12)
From: Matt Gushee <mgushee@h...>
Subject: Re: [Caml-list] Why are arithmetic functions not polymorph?
On Fri, May 23, 2003 at 01:02:33PM -0500, Brian Hurt wrote:
> On Fri, 23 May 2003 wrote:
> > > SML has a kind of operator overloading, but I don't know the details.
> > 
> > SML doesn't allow the user to define overloadings, and that is an 
> > abomination. Java is similarly abominable. 
> > 
> Ocaml allows you to define *new* operators to your heart's content.  You
> just can't overload the meanings of old operators.  And frankly, I don't
> find that abominable at all.  I don't want to turn this into a C++ 
> flamefest (had one of those already this week), but in my experience 
> operator overloading is *really* *really* bad.

Hmm, you may be right. Much of my programming experience is with Python,
where operators applied to objects are implemented as instance methods,
and can be overloaded to your heart's content. For example:

  class FunnyMoney:
      def __init__(self):
          self.balance = 0
      def __sub__(self, other):
          self.balance = self.balance + other   # BWAHAHAHAAA!

  myaccount = FunnyMoney()
  ==> 0
  myaccount - 12000000
  ==> 12000000

Of course, you can have a lot of fun with this feature. But it may be a
rather bad idea for real-world applications.

Matt Gushee                 When a nation follows the Way,
Englewood, Colorado, USA    Horses bear manure through           its fields;   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                            --Lao Tzu (Peter Merel, trans.)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: