From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 2032CBC69 for ; Sat, 12 May 2007 11:49:15 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.235]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4C9nDLo019174 for ; Sat, 12 May 2007 11:49:14 +0200 Received: by nz-out-0506.google.com with SMTP id s1so1302946nze for ; Sat, 12 May 2007 02:49:13 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=dWe/n6BGx/417dcxBaEnhXpZGb3tFVejgV/Ujx7u2uF+fU9kz8xBRv6esoJSKiTIH8Qq5R7pzNFB7AbAkOdACdNuTi+3ZDLXvU3HHIcNv1BCumw/hrR33xC0UZ1Z34MAMpgGhCfbODP80suaqnUMfv52OpRTK3RYACgcrdbpOcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SsdtbM3W/9LwIGHhquYAos2FBwvo/JM3BCBw6duJbN1uzHjYtZvkoORF+yC5LK05e36X3uXcBwYD1zvfYacJy7zAJHTxM09Y34POWtQwVwSIih4Sp/PJ3/5wwYLkobKsV48SKH8ctlBCZiN9fSDIgLQMCp8T6oZUY1eIZyFZ9ug= Received: by 10.115.91.2 with SMTP id t2mr206684wal.1178963353421; Sat, 12 May 2007 02:49:13 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Sat, 12 May 2007 02:49:13 -0700 (PDT) Message-ID: Date: Sat, 12 May 2007 11:49:13 +0200 From: "Nicolas Pouillard" To: "Jon Harrop" Subject: Re: [Caml-list] Custom operators in the revised syntax Cc: caml-list@yquem.inria.fr In-Reply-To: <200705120348.50308.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200705111537.32561.jon@ffconsultancy.com> <200705120348.50308.jon@ffconsultancy.com> X-j-chkmail-Score: MSGID : 46458D9A.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 46458D9A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 overloading:01 ocaml:01 overloading:01 overload:01 encountering:01 cheers:01 46,:98 3.3:98 wrote:01 wrote:01 caml-list:01 int:01 revised:02 float:03 On 5/12/07, Jon Harrop 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