@@ -1,12 +1,12 @@
11-- | Template Haskell support
2−--
3−-- (In a separate file for convenience)
2+{-# LANGUAGE TemplateHaskell #-}
43module Control.Distributed.Process.Internal.Closure.TH
54 ( -- * User-level API
65 remotable
76 , mkStatic
87 , functionSDict
98 , functionTDict
9+ , mkClosure
1010 ) where
1111
1212import Prelude hiding (lookup)
@@ -40,17 +40,21 @@ import Language.Haskell.TH
4040 , sigD
4141 )
4242
43−import Control.Distributed.Process.Internal.Types (Process)
44−import Control.Distributed.Process.Serializable
45− ( SerializableDict(SerializableDict)
46− )
43+import Data.Binary (encode)
44+import Data.Rank1Dynamic (toDynamic)
4745import Control.Distributed.Static
4846 ( RemoteTable
4947 , registerStatic
5048 , Static
5149 , staticLabel
50+ , Closure(Closure)
51+ , staticCompose
5252 )
53−import Data.Rank1Dynamic (toDynamic)
53+import Control.Distributed.Process.Internal.Types (Process)
54+import Control.Distributed.Process.Serializable
55+ ( SerializableDict(SerializableDict)
56+ )
57+import Control.Distributed.Process.Internal.Closure.BuiltIn (staticDecode)
5458
5559--------------------------------------------------------------------------------
5660-- User-level API --
@@ -86,6 +90,12 @@ functionSDict = varE . sdictName
8690functionTDict :: Name -> Q Exp
8791functionTDict = varE . tdictName
8892
93+mkClosure :: Name -> Q Exp
94+mkClosure n =
95+ [| Closure ($(mkStatic n) `staticCompose` staticDecode $(functionSDict n))
96+ . encode
97+ |]
98+
8999--------------------------------------------------------------------------------
90100-- Internal (Template Haskell) --
91101--------------------------------------------------------------------------------