RPC-0.3: Mechanism for (de)serializing closures for remote execution.

Safe HaskellSafe-Infered



This module provides the Serializable type class and functions to convert to and from Payloads. It's implemented in terms of the cereal package's Data.Serialize.



class (Serialize a, Typeable a) => Serializable a

Data that can be sent as a message must implement this class. The class has no functions of its own, but instead simply requires that the type implement both Typeable and Binary. Typeable can usually be derived automatically. Binary requires the put and get functions, which can be easily implemented by hand, or you can use the genericGet and genericPut flavors, which will work automatically for types implementing Data.


(Serialize a, Typeable a) => Serializable a 

serialDecode :: forall a. Serializable a => Payload -> IO (Maybe a)

data Payload


genericPut :: Data a => a -> Put

Data types that can be used in messaging must be serializable, which means that they must implement the get and put methods from Binary. If you are too lazy to write these functions yourself, you can delegate responsibility to this function. It's usually sufficient to do something like this:

 import Data.Data (Data)
 import Data.Typeable (Typeable)
 import Data.Binary (Binary, get, put)
 data MyType = MkMyType Foobar Int [(String, Waddle Baz)]
             | MkSpatula
                  deriving (Data, Typeable)
 instance Binary MyType where
    put = genericPut
    get = genericGet

genericGet :: forall a. Data a => Get a

This is the counterpart genericPut