Safe Haskell  None 

Language  Haskell2010 
Serializable closures for distributed programming. This package builds a "remotable closure" abstraction on top of static pointers. See this blog post for a longer introduction.
 type Serializable a = (Binary a, Typeable a)
 data Closure a
 closure :: StaticPtr a > Closure a
 unclosure :: Closure a > a
 cpure :: Closure (Dict (Serializable a)) > a > Closure a
 cap :: Typeable a => Closure (a > b) > Closure a > Closure b
 cmap :: Typeable a => StaticPtr (a > b) > Closure a > Closure b
 cduplicate :: Closure a > Closure (Closure a)
 newtype WrappedArrowClosure a b = WrapArrowClosure {
 unwrapClosureArrow :: Closure (a > b)
 type (/>) = WrappedArrowClosure
 data Dict a :: Constraint > * where
 class c => Static c where
Documentation
type Serializable a = (Binary a, Typeable a) Source #
Values that can be sent across the network.
Closures
Type of serializable closures. Abstractly speaking, a closure is a code
reference paired together with an environment. A serializable closure
includes a shareable code reference (i.e. a StaticPtr
). Closures can be
serialized only if all expressions captured in the environment are
serializable.
closure :: StaticPtr a > Closure a Source #
Lift a Static pointer to a closure with an empty environment.
cpure :: Closure (Dict (Serializable a)) > a > Closure a Source #
A closure can be created from any serializable value. cpure
corresponds
to Control.Applicative's pure
, but restricted to
lifting serializable values only.
cap :: Typeable a => Closure (a > b) > Closure a > Closure b Source #
Closure application. Note that Closure
is not a functor, let alone an
applicative functor, even if it too has a meaningful notion of application.
Special closures
newtype WrappedArrowClosure a b Source #
A newtypewrapper useful for defining instances of classes indexed by higherkinded types.
WrapArrowClosure  

type (/>) = WrappedArrowClosure infixr 0 Source #
Closure dictionaries
A Dict
reifies a constraint in the form of a first class value. The Dict
type is not serializable: how do you serialize the constraint that values of
this type carry? Whereas, for any constraint c
, a value of type
can be serialized and sent over the wire, just like any
Closure
(Dict
c)Closure
. A static dictionary for some constraint c
is a value of type
.Closure
(Dict
c)
data Dict a :: Constraint > * where #
Values of type
capture a dictionary for a constraint of type Dict
pp
.
e.g.
Dict
::Dict
(Eq
Int
)
captures a dictionary that proves we have an:
instance Eq
'Int
Pattern matching on the Dict
constructor will bring this instance into scope.
a :=> (Read (Dict a))  
a :=> (Monoid (Dict a))  
a :=> (Enum (Dict a))  
a :=> (Bounded (Dict a))  
() :=> (Eq (Dict a))  
() :=> (Ord (Dict a))  
() :=> (Show (Dict a))  
() :=> (Semigroup (Dict a))  
a => Bounded (Dict a)  
a => Enum (Dict a)  
Eq (Dict a)  
(Typeable Constraint p, p) => Data (Dict p)  
Ord (Dict a)  
a => Read (Dict a)  
Show (Dict a)  
Semigroup (Dict a)  
a => Monoid (Dict a)  
NFData (Dict c)  
class c => Static c where Source #
It's often useful to create a static dictionary onthefly given any
constraint. Morally, all type class constraints have associated static
dictionaries, since these are either global values or simple combinations
thereof. But GHC doesn't yet know how to invent a static dictionary ondemand
yet given any type class constraint, so we'll have to do it manually for the
time being. By defining instances of this type class manually, or via
withStatic
if it becomes too tedious.
closureDict :: Closure (Dict c) Source #