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.9 required=5.0 tests=AWL,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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 157C7BB84 for ; Thu, 14 Aug 2008 17:21:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkYCAMXpo0jRVcbvmmdsb2JhbACRQT4BAQEBAQgFCAcRA50Chn4BAoMd X-IronPort-AV: E=Sophos;i="4.32,210,1217800800"; d="scan'208";a="16119262" Received: from rv-out-0506.google.com ([209.85.198.239]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Aug 2008 17:21:28 +0200 Received: by rv-out-0506.google.com with SMTP id f6so426941rvb.3 for ; Thu, 14 Aug 2008 08:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=kZ/gltAwEvTUb7ACvLG0+rC9jW92h4F059OrKL75Upc=; b=G9xigqnp0TEGlvgFMnq6S0IzFwO+n0C/shLjVzZy2kOp0kCTCeQq6VolZvRmIxuX6g WIqwBlA6lyPau07iJSnzsz/lbg+aZzFZTXcP9Iy8I6B2RFMyLWkPtCDJdr6D9rncpjW+ SKzNKLTXuLyMZpILHdQ9FgWw49owUXZ67SYfQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=nqJLKUUHmoNzgDMW6xSXYBfJETcBEze580iWVkLDYe4Qom9LS5v4TGVwEvhtGfz1FE OIlI//9Pi21OKUHY1j8nKsNF9WlPAMJL2lodLpxNWsF9zJH9KMTACQ+Sbx4bTTuD95e9 kya1yuMxrs1uo3mBvCBYvLA2UA6Lzp6XAdFTM= Received: by 10.141.210.13 with SMTP id m13mr758689rvq.25.1218727287419; Thu, 14 Aug 2008 08:21:27 -0700 (PDT) Received: from lawn-143-215-204-204.lawn.gatech.edu ( [143.215.204.204]) by mx.google.com with ESMTPS id 30sm537872yxk.4.2008.08.14.08.21.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 14 Aug 2008 08:21:26 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Typeclasses in OCaml (Was: Haskell vs OCaml) Date: Thu, 14 Aug 2008 11:21:22 -0400 User-Agent: KMail/1.9.7 Cc: "Jim Farrand" References: In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200808141121.25463.peng.zang@gmail.com> X-Spam: no; 0.00; ocaml:01 haskell:01 ocaml:01 hash:01 inference:01 verbose:01 bool:01 bool:01 'self:01 inference:01 peng:98 peng:98 wrote:01 compile:01 meaningless:01 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 14 August 2008 10:46:41 am Jim Farrand wrote: > Things like the (=) operator in OCaml vex me. One of the big > advantages of static typing and type inference is that stupid > programmer errors are prevented at compile time. However, the (=) > operator in OCaml is effectively meaningless for a lot of types, yet > there is no way to prevent a programmer from accidentally calling it. > > One way to get around this would be to take away (=) and (==) and > replace them with specific versions for each type (just like we already > have (+) and (+.) etc) but this leads to really verbose code. > > Type classes solve this kind of problem very effectively. > > Regards, > Jim > - From what I was told earlier on this list, if you want type classes in OCaml you go with objects. So you would not have: (=) : '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. Peng -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFIpE11fIRcEFL/JewRAmyEAKCIbPDMFVh+zuCQ5uD/t+FNPXRJ2gCgwTTl ZELl4dYgZvnh8cAhlnN2gb0= =7pTp -----END PGP SIGNATURE-----