From: simonpj Date: Tue, 3 Feb 2004 16:46:33 +0000 (+0000) Subject: [project @ 2004-02-03 16:46:33 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~105 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=8628e3c4915cc7b2be85d69fa0f63706d7a3f4f1 [project @ 2004-02-03 16:46:33 by simonpj] Add comments about Template Haskell --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 025a923..baf9ef7 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -1598,7 +1598,7 @@ declarations "overlap" if type1 and type2 unify. - + However, if you give the command line option -fallow-overlapping-instances @@ -3184,6 +3184,12 @@ the background to the main technical innovations is discussed in " Template Meta-programming for Haskell" (Proc Haskell Workshop 2002). +The details of the Template Haskell design are still in flux. Make sure you +consult the online library reference material +(search for the type ExpQ). +[Temporary: many changes to the original design are described in + "http://research.microsoft.com/~simonpj/tmp/notes2.ps". +Not all of these changes are in GHC 6.2.] The first example from that paper is set out below as a worked example to help get you started. @@ -3289,6 +3295,7 @@ Tim Sheard is going to expand it.) First cut and paste the two modules below into "Main.hs" and "Printf.hs": + {- Main.hs -} module Main where @@ -3299,9 +3306,8 @@ import Printf ( pr ) -- generated at compile time by "pr" and splices it into -- the argument of "putStrLn". main = putStrLn ( $(pr "Hello") ) - - + {- Printf.hs -} module Printf where @@ -3324,14 +3330,14 @@ parse s = [ L s ] -- Generate Haskell source code from a parsed representation -- of the format string. This code will be spliced into -- the module which calls "pr", at compile time. -gen :: [Format] -> Expr +gen :: [Format] -> ExpQ gen [D] = [| \n -> show n |] gen [S] = [| \s -> s |] -gen [L s] = string s +gen [L s] = stringE s -- Here we generate the Haskell code for the splice -- from an input format string. -pr :: String -> Expr +pr :: String -> ExpQ pr s = gen (parse s)