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.8 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 552DEBBAF for ; Mon, 19 Jan 2009 17:41:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwBALw7dEnRVdsNkWdsb2JhbACTST4BAQEBCQkMBw+wf4EDjB4BAwEDhXA X-IronPort-AV: E=Sophos;i="4.37,290,1231110000"; d="scan'208";a="22716154" Received: from mail-ew0-f13.google.com ([209.85.219.13]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Jan 2009 17:41:37 +0100 Received: by ewy6 with SMTP id 6so897220ewy.3 for ; Mon, 19 Jan 2009 08:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=/NbdhxVXX/y8QhMrharWIT82LFbOJMgn9+L5WZhVPuI=; b=N/66T0NHjdxHM59cIH1KGfeCrYI9rlt+3F3EIM9TAGLSyz3Bxv4j4s4/Yp4bB0zkK6 Bhuo/5v43c65gOE8J5UmVjVTnW3LoBroxcNgIjJPjfP+R8v5RD0If55WqvO8oyYZx6GM aovy7Szkay/W4IBOlMEGGQs2SXay++XNTI7Rg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=U/vQzediXLuxKoGf34ZfuxOIBJneSOn8XjvZQbyyqxKblNukdczQWSfAseJudzOQaP t3XM68u6cdRKpmX4oVE4wZbLsMlhrWfMWyX3lsI77nB77yJqACzs4fCuNv6JklSjqfzR YVpiBsspnr7eS/sgdymwtQfr6U+EhXXIy0U5k= Received: by 10.210.112.4 with SMTP id k4mr2377757ebc.128.1232383295511; Mon, 19 Jan 2009 08:41:35 -0800 (PST) Received: by 10.210.87.13 with HTTP; Mon, 19 Jan 2009 08:41:35 -0800 (PST) Message-ID: <527cf6bc0901190841l3247ada1kfc86847aac1445d1@mail.gmail.com> Date: Mon, 19 Jan 2009 17:41:35 +0100 From: "blue storm" To: "Yoann Padioleau" Subject: Re: Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?] Cc: caml-list@yquem.inria.fr In-Reply-To: <871vuz2rm7.fsf_-_@aryx.cs.uiuc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200901171327.19141.jon@ffconsultancy.com> <200901171659.36732.jon@ffconsultancy.com> <871vuz2rm7.fsf_-_@aryx.cs.uiuc.edu> X-Spam: no; 0.00; ocaml:01 expr:01 expr:01 camlp:01 camlp:01 storm:98 folders:98 wrote:01 caml-list:01 inherit:01 match:02 inheritance:03 recurse:03 recurse:03 refine:03 On 1/19/09, Yoann Padioleau wrote: > What we want is really give code like > > let my_analysis program = > analyze_all_expressions program (fun expr -> > match expr with > | FunCall (e, es) -> do_something() > | _ -> > ) > > The problem is how to write analyze_all_expressions > and find_a_way_to_recurse_for_all_the_other_cases. You should have a look at the Camlp4 "metaprogramming" facilities : http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator You would write something like : let my_analysis program = let analysis = object (self) inherit fold as super method expr = function | FunCall (e, es) -> do_something (); self | other -> super#expr other end in analysis#expr While sometimes a bit hairy, the object oriented layer makes it easy to use a refine mapper or folders without writing all the heavy plumbing yourself.