@@ -23,8 +23,6 @@ module Control.Distributed.Process.Internal.Closure.BuiltIn
23 , cpNewChan
23 , cpNewChan
26−import Prelude hiding (snd)
27−import qualified Prelude (snd)
28import Data.ByteString.Lazy (ByteString)
26import Data.ByteString.Lazy (ByteString)
29import Data.Binary (decode, encode)
27import Data.Binary (decode, encode)
30import Data.Rank1Typeable (Typeable, ANY, ANY1, ANY2, ANY3, ANY4)
28import Data.Rank1Typeable (Typeable, ANY, ANY1, ANY2, ANY3, ANY4)
@@ -65,60 +63,42 @@ import Control.Distributed.Process.Internal.Primitives
66remoteTable :: RemoteTable -> RemoteTable
64remoteTable :: RemoteTable -> RemoteTable
67remoteTable =
65remoteTable =
68− registerStatic "$decodeDict" (toDynamic decodeDict)
66+ registerStatic "$decodeDict" (toDynamic (decodeDict :: SerializableDict ANY -> ByteString -> ANY))
69− . registerStatic "$sdictUnit" (toDynamic dictUnit)
67+ . registerStatic "$sdictUnit" (toDynamic (SerializableDict :: SerializableDict ()))
70− . registerStatic "$sdictProcessId" (toDynamic dictProcessId)
68+ . registerStatic "$sdictProcessId" (toDynamic (SerializableDict :: SerializableDict ProcessId))
71− . registerStatic "$sdictSendPort_" (toDynamic sdictSendPort_)
69+ . registerStatic "$sdictSendPort_" (toDynamic (sdictSendPort_ :: SerializableDict ANY -> SerializableDict (SendPort ANY)))
72− . registerStatic "$returnProcess" (toDynamic returnProcess)
70+ . registerStatic "$returnProcess" (toDynamic (return :: ANY -> Process ANY))
73− . registerStatic "$seqProcess" (toDynamic seqProcess)
71+ . registerStatic "$seqProcess" (toDynamic ((>>) :: Process ANY1 -> Process ANY2 -> Process ANY2))
74− . registerStatic "$bindProcess" (toDynamic bindProcess)
72+ . registerStatic "$bindProcess" (toDynamic ((>>=) :: Process ANY1 -> (ANY1 -> Process ANY2) -> Process ANY2))
75− . registerStatic "$decodeProcessId" (toDynamic decodeProcessId)
73+ . registerStatic "$decodeProcessId" (toDynamic (decode :: ByteString -> ProcessId))
76 . registerStatic "$link" (toDynamic link)
74 . registerStatic "$link" (toDynamic link)
77 . registerStatic "$unlink" (toDynamic unlink)
75 . registerStatic "$unlink" (toDynamic unlink)
78− . registerStatic "$sendDict" (toDynamic sendDict)
76+ . registerStatic "$sendDict" (toDynamic (sendDict :: SerializableDict ANY -> ProcessId -> ANY -> Process ()))
79− . registerStatic "$expectDict" (toDynamic expectDict)
77+ . registerStatic "$expectDict" (toDynamic (expectDict :: SerializableDict ANY -> Process ANY))
80− . registerStatic "$newChanDict" (toDynamic newChanDict)
78+ . registerStatic "$newChanDict" (toDynamic (newChanDict :: SerializableDict ANY -> Process (SendPort ANY, ReceivePort ANY)))
81− . registerStatic "$cpSplit" (toDynamic cpSplit)
79+ . registerStatic "$cpSplit" (toDynamic (cpSplit :: (ANY1 -> Process ANY3) -> (ANY2 -> Process ANY4) -> (ANY1, ANY2) -> Process (ANY3, ANY4)))
82− . registerStatic "$snd" (toDynamic snd)
80+ . registerStatic "$snd" (toDynamic (snd :: (ANY1, ANY2) -> ANY2))
84− decodeDict :: SerializableDict ANY -> ByteString -> ANY
82+ decodeDict :: forall a. SerializableDict a -> ByteString -> a
85 decodeDict SerializableDict = decode
83 decodeDict SerializableDict = decode
87− dictUnit :: SerializableDict ()
88− dictUnit = SerializableDict
90− dictProcessId :: SerializableDict ProcessId
91− dictProcessId = SerializableDict
93− sdictSendPort_ :: SerializableDict ANY -> SerializableDict (SendPort ANY)
85+ sdictSendPort_ :: forall a. SerializableDict a -> SerializableDict (SendPort a)
94 sdictSendPort_ SerializableDict = SerializableDict
86 sdictSendPort_ SerializableDict = SerializableDict
96− returnProcess :: ANY -> Process ANY
97− returnProcess = return
99− seqProcess :: Process ANY1 -> Process ANY2 -> Process ANY2
102− bindProcess :: Process ANY1 -> (ANY1 -> Process ANY2) -> Process ANY2
105− decodeProcessId :: ByteString -> ProcessId
106− decodeProcessId = decode
108− sendDict :: SerializableDict ANY -> ProcessId -> ANY -> Process ()
88+ sendDict :: forall a. SerializableDict a -> ProcessId -> a -> Process ()
109 sendDict SerializableDict = send
89 sendDict SerializableDict = send
111− expectDict :: SerializableDict ANY -> Process ANY
91+ expectDict :: forall a. SerializableDict a -> Process a
112 expectDict SerializableDict = expect
92 expectDict SerializableDict = expect
114− newChanDict :: SerializableDict ANY -> Process (SendPort ANY, ReceivePort ANY)
94+ newChanDict :: forall a. SerializableDict a -> Process (SendPort a, ReceivePort a)
115 newChanDict SerializableDict = newChan
95 newChanDict SerializableDict = newChan
117− cpSplit :: (ANY1 -> Process ANY3) -> (ANY2 -> Process ANY4) -> (ANY1, ANY2) -> Process (ANY3, ANY4)
97+ cpSplit :: forall a b c d. (a -> Process c) -> (b -> Process d) -> (a, b) -> Process (c, d)
118− cpSplit f g (a, b) = f a >>= \c -> g b >>= \d -> return (c, d)
98+ cpSplit f g (a, b) = do
120− snd :: (ANY1, ANY2) -> ANY2
100+ d <- g b
121− snd = Prelude.snd
101+ return (c, d)
123--------------------------------------------------------------------------------
103--------------------------------------------------------------------------------
124-- Static dictionaries and associated operations --
104-- Static dictionaries and associated operations --
@@ -164,13 +144,19 @@ type CP a b = Closure (a -> Process b)
164returnProcessStatic :: Typeable a => Static (a -> Process a)
144returnProcessStatic :: Typeable a => Static (a -> Process a)
165returnProcessStatic = staticLabel "$returnProcess"
145returnProcessStatic = staticLabel "$returnProcess"
147+-- | 'CP' version of 'Control.Category.id'
167idCP :: Typeable a => CP a a
148idCP :: Typeable a => CP a a
168idCP = staticClosure returnProcessStatic
149idCP = staticClosure returnProcessStatic
151+-- | 'CP' version of ('Control.Arrow.***')
170splitCP :: (Typeable a, Typeable b, Typeable c, Typeable d)
152splitCP :: (Typeable a, Typeable b, Typeable c, Typeable d)
171 => CP a c -> CP b d -> CP (a, b) (c, d)
153 => CP a c -> CP b d -> CP (a, b) (c, d)
172−splitCP = undefined
154+splitCP p q = cpSplitStatic `closureApplyStatic` p `closureApply` q
156+ cpSplitStatic :: Static ((a -> Process c) -> (b -> Process d) -> (a, b) -> Process (c, d))
157+ cpSplitStatic = staticLabel "$cpSplit"
159+-- | 'CP' version of 'Control.Monad.return'
174returnCP :: forall a. Serializable a
160returnCP :: forall a. Serializable a
175 => Static (SerializableDict a) -> a -> Closure (Process a)
161 => Static (SerializableDict a) -> a -> Closure (Process a)
176returnCP dict x = Closure decoder (encode x)
162returnCP dict x = Closure decoder (encode x)
@@ -180,6 +166,7 @@ returnCP dict x = Closure decoder (encode x)
180 `staticCompose`
166 `staticCompose`
181 staticDecode dict
167 staticDecode dict
169+-- | 'CP' version of ('Control.Monad.>>')
183seqCP :: (Typeable a, Typeable b)
170seqCP :: (Typeable a, Typeable b)
184 => Closure (Process a) -> Closure (Process b) -> Closure (Process b)
171 => Closure (Process a) -> Closure (Process b) -> Closure (Process b)
185seqCP p q = seqProcessStatic `closureApplyStatic` p `closureApply` q
172seqCP p q = seqProcessStatic `closureApplyStatic` p `closureApply` q
@@ -188,8 +175,9 @@ seqCP p q = seqProcessStatic `closureApplyStatic` p `closureApply` q
188 => Static (Process a -> Process b -> Process b)
175 => Static (Process a -> Process b -> Process b)
189 seqProcessStatic = staticLabel "$seqProcess"
176 seqProcessStatic = staticLabel "$seqProcess"
178+-- | (Not quite the) 'CP' version of ('Control.Monad.>>=')
191bindCP :: forall a b. (Typeable a, Typeable b)
179bindCP :: forall a b. (Typeable a, Typeable b)
192− => Closure (Process a) -> Closure (a -> Process b) -> Closure (Process b)
180+ => Closure (Process a) -> CP a b -> Closure (Process b)
193bindCP x f = bindProcessStatic `closureApplyStatic` x `closureApply` f
181bindCP x f = bindProcessStatic `closureApplyStatic` x `closureApply` f
195 bindProcessStatic :: (Typeable a, Typeable b)
183 bindProcessStatic :: (Typeable a, Typeable b)
@@ -203,23 +191,23 @@ bindCP x f = bindProcessStatic `closureApplyStatic` x `closureApply` f
203decodeProcessIdStatic :: Static (ByteString -> ProcessId)
191decodeProcessIdStatic :: Static (ByteString -> ProcessId)
204decodeProcessIdStatic = staticLabel "$decodeProcessId"
192decodeProcessIdStatic = staticLabel "$decodeProcessId"
206−-- | Closure version of 'link'
194+-- | 'CP' version of 'link'
207cpLink :: ProcessId -> Closure (Process ())
195cpLink :: ProcessId -> Closure (Process ())
208cpLink = Closure (linkStatic `staticCompose` decodeProcessIdStatic) . encode
196cpLink = Closure (linkStatic `staticCompose` decodeProcessIdStatic) . encode
210 linkStatic :: Static (ProcessId -> Process ())
198 linkStatic :: Static (ProcessId -> Process ())
211 linkStatic = staticLabel "$link"
199 linkStatic = staticLabel "$link"
213−-- | Closure version of 'unlink'
201+-- | 'CP' version of 'unlink'
214cpUnlink :: ProcessId -> Closure (Process ())
202cpUnlink :: ProcessId -> Closure (Process ())
215cpUnlink = Closure (unlinkStatic `staticCompose` decodeProcessIdStatic) . encode
203cpUnlink = Closure (unlinkStatic `staticCompose` decodeProcessIdStatic) . encode
217 unlinkStatic :: Static (ProcessId -> Process ())
205 unlinkStatic :: Static (ProcessId -> Process ())
218 unlinkStatic = staticLabel "$unlink"
206 unlinkStatic = staticLabel "$unlink"
220−-- | Closure version of 'send'
208+-- | 'CP' version of 'send'
221cpSend :: forall a. Typeable a
209cpSend :: forall a. Typeable a
222− => Static (SerializableDict a) -> ProcessId -> Closure (a -> Process ())
210+ => Static (SerializableDict a) -> ProcessId -> CP a ()
223cpSend dict pid = Closure decoder (encode pid)
211cpSend dict pid = Closure decoder (encode pid)
225 decoder :: Static (ByteString -> a -> Process ())
213 decoder :: Static (ByteString -> a -> Process ())
@@ -231,14 +219,14 @@ cpSend dict pid = Closure decoder (encode pid)
231 => Static (SerializableDict a -> ProcessId -> a -> Process ())
219 => Static (SerializableDict a -> ProcessId -> a -> Process ())
232 sendDictStatic = staticLabel "$sendDict"
220 sendDictStatic = staticLabel "$sendDict"
234−-- | Closure version of 'expect'
222+-- | 'CP' version of 'expect'
235cpExpect :: Typeable a => Static (SerializableDict a) -> Closure (Process a)
223cpExpect :: Typeable a => Static (SerializableDict a) -> Closure (Process a)
236cpExpect dict = staticClosure (expectDictStatic `staticApply` dict)
224cpExpect dict = staticClosure (expectDictStatic `staticApply` dict)
238 expectDictStatic :: Typeable a => Static (SerializableDict a -> Process a)
226 expectDictStatic :: Typeable a => Static (SerializableDict a -> Process a)
239 expectDictStatic = staticLabel "$expectDict"
227 expectDictStatic = staticLabel "$expectDict"
241−-- | Closure version of 'newChan'
229+-- | 'CP' version of 'newChan'
242cpNewChan :: Typeable a
230cpNewChan :: Typeable a
243 => Static (SerializableDict a)
231 => Static (SerializableDict a)
244 -> Closure (Process (SendPort a, ReceivePort a))
232 -> Closure (Process (SendPort a, ReceivePort a))