From: Joel Reymont <joelr1@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: AST transformation and scrapping boilerplate code
Date: Sun, 29 Apr 2007 15:40:37 +0100 [thread overview]
Message-ID: <0DF43C61-05DE-4129-A5F6-06AF8722A8D5@gmail.com> (raw)
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/
next reply other threads:[~2007-04-29 14:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-29 14:40 Joel Reymont [this message]
2007-04-30 8:21 ` [Caml-list] " Nicolas Pouillard
2007-04-30 8:41 ` Joel Reymont
2007-04-30 9:47 ` Nicolas Pouillard
2007-04-30 8:53 ` Joel Reymont
2007-04-30 12:19 ` Joel Reymont
2007-04-30 12:42 ` Nicolas Pouillard
2007-04-30 12:46 ` Joel Reymont
2007-04-30 12:58 ` Nicolas Pouillard
2007-04-30 13:06 ` Joel Reymont
2007-04-30 13:09 ` Nicolas Pouillard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0DF43C61-05DE-4129-A5F6-06AF8722A8D5@gmail.com \
--to=joelr1@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox