diff options
author | Geoffrey Mainland <mainland@apeiron.net> | 2013-06-04 16:22:06 +0100 |
---|---|---|
committer | Geoffrey Mainland <mainland@apeiron.net> | 2013-10-04 14:58:26 -0400 |
commit | 8b084408b4a937318836bd67e7264f99f04d06ce (patch) | |
tree | d5a50dfbef230a50221c4d73567498ae48f4e6ff | |
parent | bb89c59f9c489df7ef1f12e0155898d913033e12 (diff) | |
download | haskell-8b084408b4a937318836bd67e7264f99f04d06ce.tar.gz |
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.
-rw-r--r-- | libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs index b62f15a67b..11a35c1a91 100644 --- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs +++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs @@ -66,6 +66,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 -- @@ -94,6 +98,8 @@ instance Quasi IO where qAddDependentFile _ = badIO "addDependentFile" qAddTopDecls _ = badIO "addTopDecls" qAddModFinalizer _ = badIO "addModFinalizer" + qGetQ = badIO "getQ" + qPutQ _ = badIO "putQ" qRunIO m = m @@ -354,6 +360,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 @@ -367,6 +381,8 @@ instance Quasi Q where qAddDependentFile = addDependentFile qAddTopDecls = addTopDecls qAddModFinalizer = addModFinalizer + qGetQ = getQ + qPutQ = putQ ---------------------------------------------------- |