[commit: template-haskell] th-new: Add Template Haskell state. (8b8b5aa)

Geoffrey Mainland gmainlan at microsoft.com
Wed Jun 12 13:45:39 CEST 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/template-haskell

On branch  : th-new

http://hackage.haskell.org/trac/ghc/changeset/8b8b5aa1a9a8bbba056c47b1b6e03238c1f4327c

>---------------------------------------------------------------

commit 8b8b5aa1a9a8bbba056c47b1b6e03238c1f4327c
Author: Geoffrey Mainland <mainland at apeiron.net>
Date:   Tue Jun 4 16:22:06 2013 +0100

    Add Template Haskell state.
    
    The Quasi monad can now carry state, and this state can be shared amongst
    quasiquoters/splices/etc. State is stored in a finite map of Dynamic values and
    is indexed by TypeReps.

>---------------------------------------------------------------

 Language/Haskell/TH/Syntax.hs |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Language/Haskell/TH/Syntax.hs b/Language/Haskell/TH/Syntax.hs
index 6813961..51216c4 100644
--- a/Language/Haskell/TH/Syntax.hs
+++ b/Language/Haskell/TH/Syntax.hs
@@ -72,6 +72,10 @@ class (Monad m, Applicative m) => Quasi m where
 
   qAddModFinalizer :: Q () -> m ()
 
+  qGetQ :: Typeable a => m (Maybe a)
+
+  qPutQ :: Typeable a => a -> m ()
+
 -----------------------------------------------------
 --	The IO instance of Quasi
 -- 
@@ -99,6 +103,8 @@ instance Quasi IO where
   qAddDependentFile _ = badIO "addDependentFile"
   qAddTopDecls _      = badIO "addTopDecls"
   qAddModFinalizer _  = badIO "addModFinalizer"
+  qGetQ               = badIO "getQ"
+  qPutQ _             = badIO "putQ"
 
   qRunIO m = m
   
@@ -352,6 +358,14 @@ addTopDecls ds = Q (qAddTopDecls ds)
 addModFinalizer :: Q () -> Q ()
 addModFinalizer act = Q (qAddModFinalizer (unQ act))
 
+-- | Get state from the Q monad.
+getQ :: Typeable a => Q (Maybe a)
+getQ = Q qGetQ
+
+-- | Replace the state in the Q monad.
+putQ :: Typeable a => a -> Q ()
+putQ x = Q (qPutQ x)
+
 instance Quasi Q where
   qNewName  	    = newName
   qReport   	    = report
@@ -364,6 +378,8 @@ instance Quasi Q where
   qAddDependentFile = addDependentFile
   qAddTopDecls      = addTopDecls
   qAddModFinalizer  = addModFinalizer
+  qGetQ             = getQ
+  qPutQ             = putQ
 
 
 ----------------------------------------------------





More information about the ghc-commits mailing list