remote-0.1.1: Cloud Haskell



This module provides the Serializable type class and functions to convert to and from Payloads. It's implemented in terms of Haskell's Data.Binary. The message sending and receiving functionality in Remote.Process depends on this.



class (Binary a, Typeable a) => Serializable a Source

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.


genericPut :: Data a => a -> PutSource

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 :: Data a => Get aSource

This is the counterpart genericPut