Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Joel Reymont <joelr1@gmail.com>
To: O'Caml Mailing List <caml-list@yquem.inria.fr>
Subject: quasiquoting and pattern matches
Date: Fri, 17 Apr 2009 18:25:35 +0100	[thread overview]
Message-ID: <06125B5C-F0A1-465E-967E-03B125947F4B@gmail.com> (raw)

There's an example in the Geoffrey Mainland's Haskell
quasiquotation paper [1] that looks like this:

peep :: [ Asm ] -> [ Asm ]
peep [:asm| mov&s $&r1, &r2
             cmp $&r3, &r4
             je &lbl |] : rest
   | r3 = r1 ^ r4 = r2
= [:asm|  mov&s $&r1, &r2
           jmp &lbl |] : rest
...

Is it possible to do the same in OCaml, i.e. use
antiquotations in pattern matches?

I have not seen it done this way before, all the
examples match the AST, e.g. from jsgen.ml

let compile_implementation modulename expr =
   let ce =
     match expr with
       | Lprim (Psetglobal id, [e]) ->
           enter_setglobal id;
           <:stmt< var $id:jsident_of_ident id$ = $comp_expr false e$;  
 >>
       | _ -> unimplemented "compile_implementation" expr in
   let ret = (ce, !reloc_info) in
   reloc_info := [];
   ret

	Thanks, Joel

[1] http://www.eecs.harvard.edu/~mainland/ghc-quasiquoting/

---
Mac hacker with a performance bent
http://linkedin.com/in/joelreymont




                 reply	other threads:[~2009-04-17 17:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=06125B5C-F0A1-465E-967E-03B125947F4B@gmail.com \
    --to=joelr1@gmail.com \
    --cc=caml-list@yquem.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