module Control.Distributed.Process.Internal.Closure.Static
(
staticConst
, staticFlip
, staticFst
, staticSnd
, staticCompose
, staticFirst
, staticSecond
, staticSplit
, staticUnit
, staticDecode
, staticClosure
, toClosure
, sdictUnit
, sdictProcessId
, sdictSendPort
, __remoteTable
) where
import Data.Binary (encode, decode)
import Data.ByteString.Lazy (ByteString, empty)
import Data.Typeable (Typeable)
import Control.Distributed.Process.Serializable (Serializable)
import Control.Distributed.Process.Internal.Types
( Closure(Closure)
, SerializableDict(SerializableDict)
, Static
, staticApply
, ProcessId
, SendPort
)
import Control.Distributed.Process.Internal.Closure.TH (remotable, mkStatic)
import qualified Control.Arrow as Arrow (first, second, (***))
compose :: (b -> c) -> (a -> b) -> a -> c
compose = (.)
first :: (a -> b) -> (a, c) -> (b, c)
first = Arrow.first
second :: (a -> b) -> (c, a) -> (c, b)
second = Arrow.second
split :: (a -> b) -> (a' -> b') -> (a, a') -> (b, b')
split = (Arrow.***)
unit :: ()
unit = ()
decodeDict :: SerializableDict a -> ByteString -> a
decodeDict SerializableDict = decode
sdictUnit_ :: SerializableDict ()
sdictUnit_ = SerializableDict
sdictProcessId_ :: SerializableDict ProcessId
sdictProcessId_ = SerializableDict
sdictSendPort_ :: SerializableDict a -> SerializableDict (SendPort a)
sdictSendPort_ SerializableDict = SerializableDict
remotable [
'const
, 'flip
, 'fst
, 'snd
, 'compose
, 'first
, 'second
, 'split
, 'unit
, 'decodeDict
, 'sdictUnit_
, 'sdictProcessId_
, 'sdictSendPort_
]
staticConst :: (Typeable a, Typeable b) => Static (a -> b -> a)
staticConst = $(mkStatic 'const)
staticFlip :: (Typeable a, Typeable b, Typeable c)
=> Static (a -> b -> c) -> Static (b -> a -> c)
staticFlip f = $(mkStatic 'flip) `staticApply` f
staticFst :: (Typeable a, Typeable b)
=> Static ((a, b) -> a)
staticFst = $(mkStatic 'fst)
staticSnd :: (Typeable a, Typeable b)
=> Static ((a, b) -> b)
staticSnd = $(mkStatic 'snd)
staticCompose :: (Typeable a, Typeable b, Typeable c)
=> Static (b -> c) -> Static (a -> b) -> Static (a -> c)
staticCompose f x = $(mkStatic 'compose) `staticApply` f `staticApply` x
staticFirst :: (Typeable a, Typeable b, Typeable c)
=> Static ((a -> b) -> (a, c) -> (b, c))
staticFirst = $(mkStatic 'first)
staticSecond :: (Typeable a, Typeable b, Typeable c)
=> Static ((a -> b) -> (c, a) -> (c, b))
staticSecond = $(mkStatic 'second)
staticSplit :: (Typeable a, Typeable b, Typeable c, Typeable d)
=> Static (a -> c) -> Static (b -> d) -> Static ((a, b) -> (c, d))
staticSplit f g = $(mkStatic 'split) `staticApply` f `staticApply` g
staticUnit :: Static ()
staticUnit = $(mkStatic 'unit)
sdictUnit :: Static (SerializableDict ())
sdictUnit = $(mkStatic 'sdictUnit_)
sdictProcessId :: Static (SerializableDict ProcessId)
sdictProcessId = $(mkStatic 'sdictProcessId_)
sdictSendPort :: Typeable a
=> Static (SerializableDict a) -> Static (SerializableDict (SendPort a))
sdictSendPort = staticApply $(mkStatic 'sdictSendPort_)
staticDecode :: Typeable a => Static (SerializableDict a) -> Static (ByteString -> a)
staticDecode dict = $(mkStatic 'decodeDict) `staticApply` dict
staticClosure :: forall a. Typeable a => Static a -> Closure a
staticClosure static = Closure (staticConst `staticApply` static) empty
toClosure :: forall a. Serializable a
=> Static (SerializableDict a) -> a -> Closure a
toClosure dict x = Closure (staticDecode dict) (encode x)