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.6 required=5.0 tests=AWL,HTML_10_20,HTML_MESSAGE, 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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 042FBBC69 for ; Thu, 22 Feb 2007 18:21:15 +0100 (CET) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1MHLEap012633 for ; Thu, 22 Feb 2007 18:21:14 +0100 Received: by ug-out-1314.google.com with SMTP id k3so179333ugf for ; Thu, 22 Feb 2007 09:21:14 -0800 (PST) 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:references; b=AfPUWOkWn2xnvBCX6AIWLgQcNk3BuzYRoMjhIounsIwSRZOTtl+wkKnPKQwpFPilt2tlknKD6wffrIsLVEir6bNQY+L/MJdCPS1W/Y3pxlrZHLbhMLWwhJPj3tUKVUPf3MaGq3TneEDfGanMw++AYk/LkpDm8nznOTaHFdv1O28= 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:references; b=l5R1lkFqi/SFBstJdg6Zpn0QFDjmqbjhoHLzBkQ1iibuEWmZ2RB65Q+xbIl6AdghDl1wcMS0rSXL4VKdgBeUQZLJtiAt3KOmDBbozZNoQ8G5lG0gYE1L7Q+6bfWC9L4sW6P9FaoHi67W1D6u/SdnGI+vVUfxM9uBHj1WFAzrEd0= Received: by 10.82.186.5 with SMTP id j5mr213067buf.1172164873765; Thu, 22 Feb 2007 09:21:13 -0800 (PST) Received: by 10.82.100.16 with HTTP; Thu, 22 Feb 2007 09:21:13 -0800 (PST) Message-ID: Date: Thu, 22 Feb 2007 18:21:13 +0100 From: Tom To: "Joel Reymont" Subject: Re: [Caml-list] Instruction selection in the OCaml compiler: Modules or classes? Cc: caml-list@inria.fr In-Reply-To: <6CB0D237-F894-4AC3-BDBE-2BB484928D3C@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_35219_26794545.1172164873546" References: <6CB0D237-F894-4AC3-BDBE-2BB484928D3C@gmail.com> X-j-chkmail-Score: MSGID : 45DDD10A.001 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 45DDD10A.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 ocaml:01 hashes:01 compiler:01 optimise:01 caching:01 val:01 subtyping:01 hashes:01 optimise:01 caching:01 val:01 subtyping:01 integer:01 X-Attachments: cset="UTF-8" cset="UTF-8" ------=_Part_35219_26794545.1172164873546 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Classes in OCaml are indeed slow, but that is because they are incredibly different from modules. A class has fields, that is, meathods, that are "named" and searched by comparing hashes. Modules also have fields, functions and values, but they are named only as far as the programmer in concerned - in compiled code, they are indexed (by an integer), and actually, the native compiler can actually optimise even that (so only a plain function call remains). In contrast, everytime you call a method of an object, it is searched in the method list of that class (well, I think there is some caching too). But this "slowness" is expected - objects are also more adaptable than modules. If you have a function # let f o = o#some_method ();; val f : < some_method : unit -> 'a; .. > -> 'a = you can pass to it any object with method "some_method" of type unit -> 'a. That's called structural subtyping. - Tom ------=_Part_35219_26794545.1172164873546 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Classes in OCaml are indeed slow, but that is because they are incredibly different from modules. A class has fields, that is, meathods, that are "named" and searched by comparing hashes. Modules also have fields, functions and values, but they are named only as far as the programmer in concerned - in compiled code, they are indexed (by an integer), and actually, the native compiler can actually optimise even that (so only a plain function call remains). In contrast, everytime you call a method of an object, it is searched in the method list of that class (well, I think there is some caching too).

But this "slowness" is expected - objects are also more adaptable than modules. If you have a function
    # let f o = o#some_method ();;
    val f : < some_method : unit -> 'a; .. > -> 'a = <fun>
you can pass to it any object with method "some_method" of type unit -> 'a. That's called structural subtyping.

- Tom
------=_Part_35219_26794545.1172164873546--