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

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


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

On branch  : th-new

http://hackage.haskell.org/trac/ghc/changeset/a1c43c8ab095e20c799753c0aa544970e554ce89

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

commit a1c43c8ab095e20c799753c0aa544970e554ce89
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 5e967f6..6813961 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