Version française
Home     About     Download     Resources     Contact us    
Browse thread
Custom operators in the revised syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] Custom operators in the revised syntax
On 5/12/07, Jon Harrop <jon@ffconsultancy.com> wrote:
> On Friday 11 May 2007 15:46, you wrote:
> > > Operator overloading and template metaprogramming were the only things I
> > > missed moving from C++ to OCaml. :-)
> >
> > But having these custom operators reduce the pain, right?
>
> Using, +, +., +| and +|| is better than add, add_float, add_vector, add_matrix
> but allowing + to be used to all such types ('a -> 'a -> 'a) is much better
> still. It isn't even that hard to add to the language.

Not so easy too, it depends on how general your overloading system is.

Given these declarations (in an hypothetic language):

overload (+) : 'a -> 'a -> 'a;;
instance (+) Int.(+) Float.(+) Vector.(+);;

What your system should do when encountering:

let double x = x + x;;

And then:

double 1;;
double 1.1;;
double (Vector.from_array [| 1.1; 2.2; 3.3 |]);;

Cheers,

-- 
Nicolas Pouillard