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.0 required=5.0 tests=none 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 A5189BB84 for ; Sat, 17 Jan 2009 23:14:04 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqEBALvmcUnUnw6UkGdsb2JhbACCOpFKAQEBAQkJDAcRBLlVhXM X-IronPort-AV: E=Sophos;i="4.37,282,1231110000"; d="scan'208";a="21637246" Received: from fhw-relay07.plus.net ([212.159.14.148]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 17 Jan 2009 23:14:04 +0100 Received: from [87.113.104.168] (helo=leper.local) by fhw-relay07.plus.net with esmtp (Exim) id 1LOJQY-0000g1-53 for caml-list@yquem.inria.fr; Sat, 17 Jan 2009 22:14:02 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] C++/C# inheritance is bad? Date: Sat, 17 Jan 2009 22:17:56 +0000 User-Agent: KMail/1.9.9 References: <200901171659.36732.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: <200901172217.56861.jon@ffconsultancy.com> X-Plusnet-Relay: 33abf6445d9dc3b731b50a1233e9bf71 X-Spam: no; 0.00; ocaml:01 ocaml's:01 lablgtk:01 vastly:01 callbacks:01 datatypes:01 syntax:01 verbose:01 event-based:01 parsers:01 c-like:01 parallelism:01 tpl:01 recursive:01 monadic:01 On Saturday 17 January 2009 21:22:19 Kuba Ober wrote: > On Jan 17, 2009, at 11:59 AM, Jon Harrop wrote: > > On Saturday 17 January 2009 14:35:22 Kuba Ober wrote: > >> I wonder how such a hierarchy would be implemented in a natural way > >> in OCaml? > > > > Assuming you stick with accepted wisdom, you would mimic the same > > effects > > using OCaml's object system, just as LablGTK does. However, you have > > picked > > the only pedagogical OO example: GUI widgets. > > Perhaps that's where OO paradigm really shines. I'm very much against > shoehorning everything into it, of course. We've wrapped part of WPF in a functional shim for our F# for Visualization product and, even though it was originally intended for internal use only, our customers are loving using it themselves because it is vastly simpler and less error prone than trying to use WPF's own heavily-imperative but entirely thread unsafe OOP-based API directly. Also, specifying callbacks and event handlers as first-class functions is obviously preferable to an OOP-based workaround. > > In contrast, metaprogramming is the pedagogical example for algebraic > > datatypes. There is almost no need for users to extend the abstract > > syntax > > tree but there is huge value in being able to rewrite expressions > > using > > pattern matching. There is an idiomatic OOP solution to this problem > > that > > involves visitor patterns and so forth but it is comparatively > > verbose, > > obfuscated and unmaintainable. > > You've got me there -- I never liked the visitor pattern, and by > extension the event-based XML parsers written in C-like languages. Oh yes. Java is utterly intolerable in that respect. I cannot believe how popular it became despite that... Parallelism and concurrency are other examples where OOP sucks. Cilk and Microsoft's TPL are the gold standards for parallel programming right now and both are build around concurrent work stealing queues of functions waiting to be applied. This works best for divide and conquer algorithms which, in turn, lend themselves to recursive functions. The reason being that older functions on a queue are more likely to be parent functions that will spawn many offspring, so when an idle core steals from the back of another core's queue it is likely to steal a parent function that will keep it busy for some time to come. F#'s asynchronous workflows use monadic style to make concurrent programming easier. Incidentally, Cilk looks like the ideal tool to write a parallel GC... -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e