@@ -1,68 +0,0 @@
2−module Control.Distributed.Process.Internal.Closure.BuiltIn () where
13−import Data.Binary (encode)
14−import Data.Typeable (Typeable, typeOf)
15−import Control.Distributed.Process.Internal.Types
19− , SerializableDict(..)
24−import Control.Distributed.Process.Internal.TypeRep () -- Binary instances
25−import Control.Distributed.Process.Serializable (Serializable)
27−--------------------------------------------------------------------------------
29−--------------------------------------------------------------------------------
31−closureApply :: Closure (a -> b) -> Closure a -> Closure b
32−closureApply (Closure (Static labelf) envf) (Closure (Static labelx) envx) =
33− Closure (Static ClosureApply) $ encode (labelf, envf, labelx, envx)
35−closureReturn :: Serializable a => Static (SerializableDict a) -> a -> Closure a
36−closureReturn (Static dict) x = Closure (Static ClosureReturn) (encode (dict, x))
38−closureStatic :: Static a -> Closure a
39−closureStatic (Static dict) = Closure (Static ClosureStatic) (encode dict)
41−--------------------------------------------------------------------------------
42−-- Polymorphic closures --
44−-- TODO: These functions take a SerializableDict as argument. When we get --
45−-- proper support for static, ideally this argument disappears completely; --
46−-- but if not, it should turn into a static (SerializableDict a). We don't --
47−-- require them to be "static" here because we don't have a pure 'unstatic' --
48−-- function, and hence have no way of turning a static (SerializableDict a) --
49−-- into an actual SerialziableDict a (we need that in order to pattern match --
50−-- on the dictionary and bring the type class dictionary into scope, so that --
51−-- we can call 'encode' (for instance in 'returnClosure'). --
52−--------------------------------------------------------------------------------
54−-- | Closure version of 'send'
55−sendClosure :: forall a. SerializableDict a -> ProcessId -> Closure (a -> Process ())
56−sendClosure SerializableDict pid =
57− Closure (Static ClosureSend) (encode (typeOf (undefined :: a), pid))
60−returnClosure :: forall a. SerializableDict a -> a -> Closure (Process a)
61−returnClosure SerializableDict val =
62− Closure (Static ClosureReturn) (encode (typeOf (undefined :: a), encode val))
64−-- | Closure version of 'expect'
65−expectClosure :: forall a. SerializableDict a -> Closure (Process a)
66−expectClosure SerializableDict =
67− Closure (Static ClosureExpect) (encode (typeOf (undefined :: a)))