Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 brogoff@speakeasy.net 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()
  myaccount.balance
  ==> 0
  myaccount - 12000000
  myaccount.balance
  ==> 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
mgushee@havenrock.com           its fields;
http://www.havenrock.com/   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                                
                            --Lao Tzu (Peter Merel, trans.)

-------------------
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