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=2.8 required=5.0 tests=DNS_FROM_RFC_POST,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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id EFC45BB84 for ; Thu, 14 Aug 2008 18:04:25 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkYCABX0o0hC+VLvmmdsb2JhbACRQT4BAQEBAQgFCAcRA5xbhnIBAoNn X-IronPort-AV: E=Sophos;i="4.32,210,1217800800"; d="scan'208";a="15996385" Received: from wx-out-0506.google.com ([66.249.82.239]) by mail3-smtp-sop.national.inria.fr with ESMTP; 14 Aug 2008 18:04:25 +0200 Received: by wx-out-0506.google.com with SMTP id i30so804695wxd.15 for ; Thu, 14 Aug 2008 09:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=JOiEXIKkY734Ck9msJEyZjK2v2GQYJlb1DtKbvRWMV0=; b=L/Ya2Wj3rPzj+reWEzpkukWH0FTcNDdmHw2Z2YosnbfOoE+i0kSlii/KZZT2djB/Jx oME4Z6/+Qee0W4oEiwndiJk6veXMCsQBFFygDsTtBhHNxLHkHIZeMueu4MGcLeMQzmNd M+74nwjVnFvsXYAEQqU2HdrDxLcmsl5NdapIQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=tpAJd6QNStByZd2RJu6gthGvkZmblhJU5ztwgm78BrJ+Fxu26z869ZVdUPkC+pD6cp wi2QcCEge0FJ1T3n5ko9K1S879VSr54smMDsFDULdWGV7e6QUcvdhwzvRBiwki4yIEgB lkgb1H+aaDAu9PmCcotJg10PKv7lC1YmI1OxE= Received: by 10.114.148.2 with SMTP id v2mr1382474wad.202.1218729863638; Thu, 14 Aug 2008 09:04:23 -0700 (PDT) Received: by 10.115.111.4 with HTTP; Thu, 14 Aug 2008 09:04:23 -0700 (PDT) Message-ID: Date: Thu, 14 Aug 2008 17:04:23 +0100 From: "Jim Farrand" Sender: jim.farrand@gmail.com To: "Caml Mailing List" Subject: Re: [Caml-list] Typeclasses in OCaml (Was: Haskell vs OCaml) In-Reply-To: <200808141121.25463.peng.zang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200808141121.25463.peng.zang@gmail.com> X-Google-Sender-Auth: 42077506ff45ea18 X-Spam: no; 0.00; ocaml:01 haskell:01 ocaml:01 bool:01 bool:01 'self:01 inference:01 undecidable:01 haskell:01 runtime:01 subclassing:01 peng:98 peng:98 typing:01 typing:01 2008/8/14 Peng Zang : > (=) : 'a -> 'a -> bool > > But instead: > > (=) : (#equatable as 'a) -> 'a -> bool > > where > > class type equatable = object > method equals : 'self -> bool > end > > > This gives all the advantages of static typing and type inference and prevents > stupid errors and it is meaningful for all types that it is implemented for. This doesn't answer my question at all. :) Is there any theoretical reason they couldn't added? The kind of answer I'm looking for is "There is no theoretical reason why not", or "This is impossible as it would cause typing in OCaml to become undecidable, due to interactions with other features of the OCaml type system which aren't present in Haskell." Though, to address your solution, I am of course aware of it, but it has what seem like big disadvantages: 1. Every value in OCaml would then have to be an object 2. Every comparison now requires a relatively expensive dynamic dispatch, when the correct function could be determined at runtime. 3. If I add a new operator that wasn't thought of by the language implementors, it can't be easily added to primitive values, without either subclassing all of them, or changing the definition in the standard library to add the new method. Regards, Jim