Some notes about «Syntactic Meta-programming features in OCaml and Haskell»

Nicolas Pouillard

Sep 13 2012, ML Workshop

Overview

In-language support to avoid syntactic features

Parsing technologies

Haskell syntax library in Template Haskell

data Exp
  = VarE Name
  | ConE Name
  | LitE Lit
  | AppE Exp Exp
  | ...

type ExpQ = Q Exp
data Type
  = ...
  | VarT Name
  | ConT Name
  | ...


type TypeQ = Q Type

Quotations, Quasiquotes

(* SQL expression *)
<:sql< SELECT * FROM person where name = Joe >>
(* OCaml type expression *)
<:ctyp< int list -> bool >>
-- C expression
[cexp|(1)? 2 : (3 + 4)|]
-- Haskell type expression
[typ|List Int -> Bool|]

Splicing/Quoting in Template Haskell

$(deriveFoo ''Bar)
foo :: $(genTypeAbout ''Bar)
foo = $(genExprAbout ''Bar)

Misc points