Version française
Home     About     Download     Resources     Contact us    
Browse thread
quasiquoting and pattern matches
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: quasiquoting and pattern matches
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