[Haskell-cafe] Haskell syntax inside QuasiQuote

Reiner Pope reiner.pope at gmail.com
Mon Oct 20 06:53:51 EDT 2008


Hi,

I have written a toy fixed-length-vector quasiquoter, so that you can write

[$vec|1,2|]

which has its type inferred as (Vec (S (S Z))) and you can write

mkVec :: Double -> Vec (S (S (S Z)))
mkVec x = [$vec|1,2,x|]

However, these above examples essentially demonstrate the entire syntax it
supports: number literals, and anti-quoted variables.

I would like to extend my quasiquoter to support Haskell's full expression
syntax, so that we can write, for example,

mkVec2 x = [$vec| if x > 5 then sin x else cos x |]

Is there a simple way to do this, i.e. using existing libraries? What I need
is a Haskell expression parser which outputs values of type
Language.Haskell.TH.Syntax.QExp, but I can't see one available in the TH
libraries, or in the haskell-src(-exts) libraries.

Thoughts?

Cheers,

Reiner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081020/4704fac4/attachment.htm


More information about the Haskell-Cafe mailing list