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=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 32632BBC4 for ; Wed, 4 Mar 2009 02:54:28 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnEBAIBurUnUnwckjmdsb2JhbACCHZJqAQEBAQkLCAkPBsEohAgG X-IronPort-AV: E=Sophos;i="4.38,297,1233529200"; d="scan'208";a="36053040" Received: from relay.ptn-ipout02.plus.net ([212.159.7.36]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 04 Mar 2009 02:54:27 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ar8EAAdurUnUnw6S/2dsb2JhbACCHdRZhAgG Received: from ptb-relay02.plus.net ([212.159.14.146]) by relay.ptn-ipout02.plus.net with ESMTP; 04 Mar 2009 01:54:27 +0000 Received: from [87.112.234.120] (helo=leper.local) by ptb-relay02.plus.net with esmtp (Exim) id 1LegJW-0007M3-U2; Wed, 04 Mar 2009 01:54:27 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: Brian Hurt , caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? Date: Wed, 4 Mar 2009 01:59:48 +0000 User-Agent: KMail/1.9.9 References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <200903032342.39527.jon@ffconsultancy.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903040159.48574.jon@ffconsultancy.com> X-Plusnet-Relay: 15f7845ca7cc1924d42bf4c9f529184d X-Spam: no; 0.00; stl:01 functors:01 ocaml:01 functors:01 ocaml:01 haskell:01 inlining:01 abstracting:01 haskell:01 abstraction:01 haskell's:01 functor:01 overloading:01 functor:01 overloading:01 On Wednesday 04 March 2009 00:11:32 you wrote: > On Tue, 3 Mar 2009, Jon Harrop wrote: > > Functors give you the same capability in OCaml but they are rarely used > > precisely because the functionality is not very useful. Also largely because there is not enough good tutorial information available explaining how to leverage functors. > I think I disagree with this. I think functors aren't used very much in > Ocaml because: > 1) They're a big, scary name, and > 2) They're slightly less efficient. > > The biggest difference between Haskell and Ocaml that I see is simply the > difference between attitudes of the two communities. The Ocaml community > is like "Don't use functors- they disable inlining and cost you six whole > clock cycles on a function call! They're evil, I tell you!" Efficiency is only important in the context of functors when abstracting very fast and common functions like arithmetic without defunctorizing your code. I don't think that is why people avoid functors in OCaml. > Meanwhile, > the Haskell community is like "I used typeclasses all over my application, > and the performance didn't completely suck- woot! Type classes rule!" > This is a broad generalization, and not completely accurate- but on the > whole, the ocaml community is much more focused on (clock cycle) > efficiency, while the Haskell community is much more focused on > abstraction and programmer-cycle efficiency. I think that is a reflection of what the communities desire rather than what they already have. OCaml is already fast (particularly on amd64) but OCamlers always want even better performance. Haskell's development experience is a real sore point and they want to address that. However, I would also say that both communities are moving very slowly toward these goals. > The type classes comparison isn't even an analogy- it's a precise > relationship. Anywhere you might be thinking, in Ocaml, "this would be a > nice place to use a type class", use a functor. You want operator > overloading in Ocaml? You got it: use a functor. Functors do not facilitate operator overloading. You still end up with a combinatorial explosion in the number of operator names. > If this causes you a > knee jerk reaction about performance, ask yourself this: do you know how > type classes are implemented in Haskell, and what their performance hit > there is? Now, imagine programming haskell where typeclasses are only > used in a very places- Ord, Eq, Monad. No Num. No Monoid. No Show. > That's Ocaml. Not that it has to be. I don't follow your breakdown. OCaml does not have Ord and Eq, it only has a hack for structural equality. Same for Show. Few people care about Monad, Num and Monoid. However, that is trivial to fix with run-time type information that can convey per-type functions. Both F# and my HLVM already do that. > Having actually used Haskell for a while, I think I actually like functors > better than type classes. But that's a rant for a different venue. The > big difference is that Haskell programmers use type classes, and the Ocaml > programmers don't use Functors (very often, if at all). There are some very good examples of functors out there, like ocamlgraph. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e