[Template-haskell] using template haskell to implement pads for haskell?

Marc Weber marco-oweber at gmx.de
Sun Jun 29 19:02:17 EDT 2008


Hi Dave,

I think I don't have to tell you much about template-haskell because
there is a small wiki page.

To get started try:
ghci -fth
:m +Language.Haskell.TH
:m +Language.Haskell.TH.Syntax
pprint <<= runQ [| (\a -> a +7 ) |]
[d|  |] top level declarations
[t|  |] types
[| |] code you can use in the middle anywhere

The cool thing now is that you can use pprint as shown above to pretty
print the automatically generated human readable haskell code and ouput
it using 
$( runIO $ do putStrLn "test" >> hFlush stdout )
With some simple substitutions you can make compilable code out of that
(Eg removing GHC.Base.  and so on)
So you get both: Generated code, but you can also directly read the
description from file and generate your code on the fly while compiling.

The ghci approach works nicely, however in you propably want to use the
helper functions found in Langauge.Haskell.TH.Lib.

There is an alternative: DrIft which derives some instances
automatically. Get the source and have a look at those examples.

Looking at hackage there is another alternative: 
        # haskell-src library: Manipulating Haskell source code
        # haskell-src-exts library: Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer

On Sun, Jun 29, 2008 at 03:25:47PM -0400, David Walker wrote:
>  hi,
> 
>  I am new to Haskell and even more so to Haskell templates -- if there
>  is an obvious answer to my question, please just point me at the
>  relevant URL.  Thanks! (If you think I should email this query to
>  a broader Haskell mailing list let me know too.)
> 
>  My friends and I are thinking about adding an extension to Haskell to
>  implement a variant of the PADS domain-specific language.  PADS is a
>  convenient syntax to describe a file format and generate a bunch of
>  tools for it such as parser, printer, xml translator, semi-structured
>  query engine, statistical profiler, etc.  (We also have tools to
Query enginge ? is this xml only?
I'm asking because I'm working on a very small RDBM replacement holding
data in memory only which can be used with HAppS state easily. I've
nearly finished modeling inserting/ updating rows but I'm still unsure
how to write a good (dynamic) query engine for it because some queries
are know at run time only (eg when unsing different filters within web
applications)..

>From hackage this might be interesting as well:
HXQ library and program: A Compiler from XQuery to Haskell

Sincerly
Marc Weber


More information about the template-haskell mailing list