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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 787F0BB84 for ; Thu, 14 Aug 2008 16:46:44 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkkCAJHho0hKfSwelGdsb2JhbACRQT4BAQEBCQMKBxEDnQeGfQECg2c X-IronPort-AV: E=Sophos;i="4.32,210,1217800800"; d="scan'208";a="16118426" Received: from yx-out-2324.google.com ([74.125.44.30]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Aug 2008 16:46:44 +0200 Received: by yx-out-2324.google.com with SMTP id 3so342498yxj.3 for ; Thu, 14 Aug 2008 07:46:42 -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:mime-version:content-type:content-transfer-encoding :content-disposition:x-google-sender-auth; bh=+iglH43R7H3oItHomDOPhF7EDA6EYEPCK+DGJuJYbm4=; b=dOSXc2X84S/DRlbBv+o2GqsuUtuaEWO1ff0Lq3OZKroVgybH8ZX4So09VVBo1epoSq 7CL1iHALmX2mPo8zSDU2jTItEJsB1ERGAsw0+YNV3E3T+XoJkkWYprOo0GZ2IH5hwtJn GWSeG9aT4XQfzztwwXkqPlyDIDY5/dnEdmabY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition:x-google-sender-auth; b=MeoOTMDaN542j86dk1CZusiZuyD+Y3NwaOatQhUgltQIbRKPh81lq06C09aQwJRfBw XkbFnh7cIT7SYzeCJK1ssS6JVmA3GbREO0NADRFyaECTMq/UtPQ+LDsam5TH6ML/V8Z1 IU4rkNYYkInyTDdEs4xxZRRuvLznQe2aLq0Zg= Received: by 10.114.39.5 with SMTP id m5mr1247549wam.113.1218725201502; Thu, 14 Aug 2008 07:46:41 -0700 (PDT) Received: by 10.115.111.4 with HTTP; Thu, 14 Aug 2008 07:46:41 -0700 (PDT) Message-ID: Date: Thu, 14 Aug 2008 15:46:41 +0100 From: "Jim Farrand" Sender: jim.farrand@gmail.com To: "Caml Mailing List" Subject: Typeclasses in OCaml (Was: Haskell vs OCaml) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 32779c9be7393731 X-Spam: no; 0.00; ocaml:01 haskell:01 ocaml:01 haskell:01 sig:01 syntax:01 inference:01 verbose:01 peng:98 peng:98 compile:01 meaningless:01 typing:01 theoretical:03 static:03 2008/8/14 Peng Zang : > In Haskell you can write a function that takes anything that is "showable" (a > type class) and print it out. The sig would be something like (I'm mixing > OCaml and Haskell syntax here, but hopefully the point is still clear): Out of curiosity, are there any theoretical reasons why OCaml could not be extended with type classes? They are one of my favourite features of Haskell, and I think they would really improve OCaml. 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