[commit: packages/template-haskell] wip/th-new: Add support for top-level finalizers (e8ac00c)

git at git.haskell.org git
Fri Oct 4 21:51:15 UTC 2013


Repository : ssh://git at git.haskell.org/template-haskell

On branch  : wip/th-new
Link       : http://git.haskell.org/packages/template-haskell.git/commitdiff/e8ac00ce079abd87396e3413ee4159f8b54e80dd

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

commit e8ac00ce079abd87396e3413ee4159f8b54e80dd
Author: Geoffrey Mainland <mainland at apeiron.net>
Date:   Tue Jun 4 13:58:52 2013 +0100

    Add support for top-level finalizers


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

e8ac00ce079abd87396e3413ee4159f8b54e80dd
 Language/Haskell/TH/Syntax.hs |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Language/Haskell/TH/Syntax.hs b/Language/Haskell/TH/Syntax.hs
index 79e2944..b62f15a 100644
--- a/Language/Haskell/TH/Syntax.hs
+++ b/Language/Haskell/TH/Syntax.hs
@@ -64,6 +64,8 @@ class (Monad m, Applicative m) => Quasi m where
 
   qAddTopDecls :: [Dec] -> m ()
 
+  qAddModFinalizer :: Q () -> m ()
+
 -----------------------------------------------------
 --	The IO instance of Quasi
 --
@@ -91,6 +93,7 @@ instance Quasi IO where
   qRecover _ _ 	      = badIO "recover" -- Maybe we could fix this?
   qAddDependentFile _ = badIO "addDependentFile"
   qAddTopDecls _      = badIO "addTopDecls"
+  qAddModFinalizer _  = badIO "addModFinalizer"
 
   qRunIO m = m
 
@@ -346,6 +349,11 @@ addDependentFile fp = Q (qAddDependentFile fp)
 addTopDecls :: [Dec] -> Q ()
 addTopDecls ds = Q (qAddTopDecls ds)
 
+-- | Add a finalizer that will run in the Q monad after the current module has
+-- been type checked. This only makes sense when run within a top-level splice.
+addModFinalizer :: Q () -> Q ()
+addModFinalizer act = Q (qAddModFinalizer (unQ act))
+
 instance Quasi Q where
   qNewName  	    = newName
   qReport   	    = report
@@ -358,6 +366,7 @@ instance Quasi Q where
   qRunIO    	    = runIO
   qAddDependentFile = addDependentFile
   qAddTopDecls      = addTopDecls
+  qAddModFinalizer  = addModFinalizer
 
 
 ----------------------------------------------------




More information about the ghc-commits mailing list