[commit: template-haskell] th-new-7.6: Add support for top-level finalizers (8a0fb5e)

Geoffrey Mainland gmainlan at microsoft.com
Wed Jun 12 12:04:26 CEST 2013


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

On branch  : th-new-7.6

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

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

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

    Add support for top-level finalizers

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

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

diff --git a/Language/Haskell/TH/Syntax.hs b/Language/Haskell/TH/Syntax.hs
index acca18d..f795f87 100644
--- a/Language/Haskell/TH/Syntax.hs
+++ b/Language/Haskell/TH/Syntax.hs
@@ -70,6 +70,8 @@ class (Monad m, Applicative m) => Quasi m where
 
   qAddTopDecls :: [Dec] -> m ()
 
+  qAddModFinalizer :: Q () -> m ()
+
 -----------------------------------------------------
 --	The IO instance of Quasi
 -- 
@@ -96,6 +98,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
   
@@ -344,6 +347,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
@@ -355,6 +363,7 @@ instance Quasi Q where
   qRunIO    	    = runIO
   qAddDependentFile = addDependentFile
   qAddTopDecls      = addTopDecls
+  qAddModFinalizer  = addModFinalizer
 
 
 ----------------------------------------------------





More information about the ghc-commits mailing list