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

git at git.haskell.org git at git.haskell.org
Mon Sep 23 07:59:26 CEST 2013


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

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

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

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

    Add support for top-level finalizers


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

30d359db997ea0288b88ae862efb8a3ea22b859c
 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 41b379b..fb4873f 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