@@ -50,7 +50,7 @@ module Control.Distributed.Process.Closure
5050import Prelude hiding (lookup)
5151import Data.ByteString.Lazy (ByteString)
5252import Data.Binary (encode, decode)
53−import Data.Typeable (typeOf)
53+import Data.Typeable (typeOf, TypeRep, Typeable)
5454import Control.Applicative ((<$>))
5555import Language.Haskell.TH
5656 ( -- Q monad and operations
@@ -111,9 +111,20 @@ mkClosure = varE . closureName
111111-- Closure combinators --
112112--------------------------------------------------------------------------------
113113
114−bindCP :: Closure (Process a) -> Closure (a -> Process b) -> Closure (Process b)
115−bindCP (Closure (Static x) envx) (Closure (Static f) (envf)) =
116− Closure (Static "$bind") (encode ((x, envx), (f, envf)))
114+applyClosure :: Closure (a -> b) -> Closure a -> Closure b
115+applyClosure (Closure (Static labelf) envf) (Closure (Static labelx) envx) =
116+ Closure (Static "$applyClosure") $ encode (labelf, envf, labelx, envx)
117+
118+liftedBind :: forall a b. (Typeable a, Typeable b)
119+ => Closure (Process a -> (a -> Process b) -> Process b)
120+liftedBind = Closure (Static "$liftedBind") (encode typ)
121+ where
122+ typ :: TypeRep
123+ typ = typeOf (undefined :: Process a -> (a -> Process b) -> Process b)
124+
125+bindCP :: (Typeable a, Typeable b)
126+ => Closure (Process a) -> Closure (a -> Process b) -> Closure (Process b)
127+bindCP x f = liftedBind `applyClosure` x `applyClosure` f
117128
118129--------------------------------------------------------------------------------
119130-- Internal (Template Haskell) --