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.1 required=5.0 tests=AWL,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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 28D5DBC69 for ; Sun, 29 Apr 2007 16:40:42 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3TEefsg029866 for ; Sun, 29 Apr 2007 16:40:41 +0200 Received: by ug-out-1314.google.com with SMTP id k3so922480ugf for ; Sun, 29 Apr 2007 07:40:41 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=uQgL36PbiPE2BJNNfkuHLw54h+Af0dJ6U394WGcQKJ2gQ9kwB2T4+NzPk2jnYx3Vm7dcm1qtB939PYE0YKaVdMvesYw5A+i1RGlb7wCa41ACp+ugizIlFuims7LIg7ZzVyi+sFtHrsOVTPyPWTZ7btD8ZYD8jhz+jB+tRifKNak= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=Mhbf7dTeDm4ONLCSbB2Odi5pg7aeVVh9JzurRaY6mMlfDKl1ptG2Q69+iDdxZ0873R2mVCf70gXUJSe8lSzOGlpN5yZzHIo5DwOLw1uCALuAtHQCt8mKokcYR2zUoNm1uv7fPcypipRZQVJA4ieVNCF0I5x9mStdh/oISQ6Eqh8= Received: by 10.67.10.18 with SMTP id n18mr4635332ugi.1177857641601; Sun, 29 Apr 2007 07:40:41 -0700 (PDT) Received: from ?192.168.1.34? ( [81.37.190.201]) by mx.google.com with ESMTP id y37sm8024403iky.2007.04.29.07.40.40; Sun, 29 Apr 2007 07:40:40 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) Content-Transfer-Encoding: 7bit Message-Id: <0DF43C61-05DE-4129-A5F6-06AF8722A8D5@gmail.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: Caml List From: Joel Reymont Subject: AST transformation and scrapping boilerplate code Date: Sun, 29 Apr 2007 15:40:37 +0100 X-Mailer: Apple Mail (2.752.3) X-j-chkmail-Score: MSGID : 4634AE69.000 on discorde : j-chkmail score : XXX : 5/20 1 0.000 -> 3 X-Miltered: at discorde with ID 4634AE69.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; haskell:01 ocaml:01 invokes:01 constructors:01 expr:01 decl:01 decl:01 expr:01 scrap:98 feat:98 instrument:98 token:01 recursively:01 data:02 mul:02 Folks, I have a large AST [2] that I would like to strip of token locations. Using the "Scrap your boilerplate" approach [1] the Haskell code looks like this: strip :: (Data a) => a -> a strip = everywhere (mkT f) where f (TokenPos a _) = a f x = x Is there a way to accomplish a similar feat in OCaml without writing out heaps of code that recursively invokes strip for various constructors to get to expr and strip it of TokenPos? Thanks, Joel [1] http://tinyurl.com/36jj3q [2] Incomplete AST let statement = [ ... | `InputDecls of input_decl list | `VarDecls of var_decl list ... ] and subscript = expr list and input_decl = [ | `InputDecl of id * ty * expr | `FunArgDecl of id * ty * subscript ] and expr = [ ... | `FunCall of ty * string * expr list * bars_ago * instrument | `Mul of expr * expr ... | `PrintExpr of expr * expr * expr ... | `TokenPos of expr * pos list ] -- http://wagerlabs.com/