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=AWL 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 21A9DBBCA for ; Wed, 27 Feb 2008 12:02:47 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAHDSxEdT9QHmZmdsb2JhbACBVo8RCwQFAQcJGYENmzw X-IronPort-AV: E=Sophos;i="4.25,412,1199660400"; d="scan'208";a="8650390" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Feb 2008 12:02:47 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1RB2kYR005337 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 27 Feb 2008 12:02:46 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAHDSxEdT9QHmZmdsb2JhbACBVo8RCwQFAQcJGYENmzw X-IronPort-AV: E=Sophos;i="4.25,412,1199660400"; d="scan'208";a="8650389" Received: from pop.bulldoghome.com (HELO bdmail1.accesst.com) ([83.245.1.230]) by mail1-smtp-roc.national.inria.fr with ESMTP; 27 Feb 2008 12:02:46 +0100 Received: from host-84-9-232-196.dslgb.com ([84.9.232.196] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1JUK1D-0004f2-So; Wed, 27 Feb 2008 11:00:12 +0000 Message-ID: <47C541FB.30508@ed.ac.uk> Date: Wed, 27 Feb 2008 10:56:59 +0000 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) MIME-Version: 1.0 To: Markus Mottl Cc: David Teller , OCaml Subject: Re: [Caml-list] Deriving + type-conv + OCaml-Templates + camlp4* = ? References: <1204057629.6163.50.camel@Blefuscu> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 47C54356.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 markus:01 mottl:01 ens-lyon:01 ocaml:01 camlp:01 trade-offs:01 variants:01 recursion:01 endline:01 recursion:01 syntax:01 normalized:01 26,:98 polymorphic:01 Markus Mottl wrote: > On Tue, Feb 26, 2008 at 3:27 PM, David Teller > wrote: >> Browsing around the net, I've found three >> "scrap-your-boilerplate"-style projects for OCaml: the simple >> Type-conv, the ambitious Deriving and the unmaintained >> OCaml-Templates, and of course the ability to use camlp4/camlp5 for >> the same purpose. I imagine that there are a number of nice >> boilerplate-based modules just waiting to be implemented or >> adopted. >> >> As far as I understand, there's no interaction between the project >> authors, which is a shame. So this is an open call to whoever is in >> charge of each work: do you think it would be possible for you all >> to join forces and produce something robust, simple and possible to >> adopt as a standard ? > > I think that different projects have different trade-offs that are > hard, if not impossible, to combine. I fear that you may be right, although (as the author of deriving) I'd be more than happy to consider collaboration, given a concrete proposal. > Deriving is a very elegant, general approach, but last time I checked > it would be hard to generate highly optimized code with it, Thanks for the kind words! I expect you're right about generating optimized code; as you suggest this hasn't been a focus. Performance of generated code should be at least reasonable, though, and it is possible to substitute handwritten code at critical points, as with any such approach. > and it was also not complete (e.g. handling hard cases like > polymorphic variants with inherited types, etc.). This is a little more surprising, since completeness *is* a focus of deriving. If I understand you rightly, then the case you mention is actually handled: are you referring to using deriving with a polymorphic variant type that extends another, such as type a = [`A] type ab = [a|`B] ? This sort of thing is certainly handled; indeed, deriving handles considerably more complicated cases as well, e.g. involving various sorts of recursion: type ('a,'b) x = [`One of 'a | `Two of 'b] deriving (Show) type 'a y = [`Four of ([('z,'a) x | `Three] as 'z)] deriving (Show) type z = z y deriving (Show) let _ = print_endline (Show.show (`Four (`One (`Two (`Four `Three))))) In fact, the way that deriving treats structural types with inline recursion (i.e. the "as" syntax) is perhaps an example of a difficulty in combining projects: deriving converts types into a normalized representation in which this recursion is shifted to the type declaration level: a sort of ANF for types. This works well (and makes it much easier to write new generic functions, since it removes the need to deal with "as"), but might be a little heavyweight for projects with other focuses. To avoid giving the impression that deriving is absolutely complete, I should mention that nested (i.e. irregular) types are not handled. This is in some ways a limitation of the approach of using modules for recursion. I don't think this limitation is significant for most people, but I may look into adding support at some point. Jeremy.