Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Distributed.Closure
Description
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.
Synopsis
- 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 where
- class c => Static c where
- closureDict :: Closure (Dict c)
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.
Instances
StaticApplicative Closure Source # | |
Defined in Control.Applicative.Static | |
StaticApply Closure Source # | |
Defined in Control.Applicative.Static | |
StaticComonad Closure Source # | |
Defined in Control.Comonad.Static Methods staticExtract :: Typeable a => Closure a -> a Source # | |
StaticExtend Closure Source # | |
StaticBind Closure Source # | |
StaticFunctor Closure Source # | |
IsStatic Closure Source # | |
Defined in Control.Distributed.Closure.Internal Methods fromStaticPtr :: Typeable a => StaticPtr a -> Closure a # | |
Typeable a => Binary (Closure a) Source # | |
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 newtype-wrapper useful for defining instances of classes indexed by higher-kinded types.
Constructors
WrapArrowClosure | |
Fields
|
Instances
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)
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:
instanceEq
Int
Pattern matching on the Dict
constructor will bring this instance into scope.
Instances
() :=> (Semigroup (Dict a)) | |
() :=> (Show (Dict a)) | |
() :=> (Eq (Dict a)) | |
() :=> (Ord (Dict a)) | |
a :=> (Monoid (Dict a)) | |
a :=> (Bounded (Dict a)) | |
a :=> (Enum (Dict a)) | |
a :=> (Read (Dict a)) | |
HasDict a (Dict a) | |
Defined in Data.Constraint | |
c => Boring (Dict c) | |
Defined in Data.Constraint | |
NFData (Dict c) | |
Defined in Data.Constraint | |
a => Monoid (Dict a) | |
Semigroup (Dict a) | |
(Typeable p, p) => Data (Dict p) | |
Defined in Data.Constraint Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Dict p -> c (Dict p) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Dict p) # toConstr :: Dict p -> Constr # dataTypeOf :: Dict p -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Dict p)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Dict p)) # gmapT :: (forall b. Data b => b -> b) -> Dict p -> Dict p # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQ :: (forall d. Data d => d -> u) -> Dict p -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Dict p -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # | |
a => Bounded (Dict a) | |
a => Enum (Dict a) | |
Defined in Data.Constraint | |
a => Read (Dict a) | |
Show (Dict a) | |
Eq (Dict a) | |
Ord (Dict a) | |
class c => Static c where Source #
It's often useful to create a static dictionary on-the-fly 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 on-demand
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.
Methods
closureDict :: Closure (Dict c) Source #
Instances
(Static c1, Static c2, Typeable c1, Typeable c2, (c1, c2)) => Static (c1, c2) Source # | |
Defined in Control.Distributed.Closure Methods closureDict :: Closure (Dict (c1, c2)) Source # | |
(Static c1, Static c2, Static c3, Typeable c1, Typeable c2, Typeable c3, (c1, c2, c3)) => Static (c1, c2, c3) Source # | |
Defined in Control.Distributed.Closure Methods closureDict :: Closure (Dict (c1, c2, c3)) Source # | |
(Static c1, Static c2, Static c3, Static c4, Typeable c1, Typeable c2, Typeable c3, Typeable c4, (c1, c2, c3, c4)) => Static (c1, c2, c3, c4) Source # | |
Defined in Control.Distributed.Closure Methods closureDict :: Closure (Dict (c1, c2, c3, c4)) Source # | |
(Static c1, Static c2, Static c3, Static c4, Static c5, Typeable c1, Typeable c2, Typeable c3, Typeable c4, Typeable c5, (c1, c2, c3, c4, c5)) => Static (c1, c2, c3, c4, c5) Source # | |
Defined in Control.Distributed.Closure Methods closureDict :: Closure (Dict (c1, c2, c3, c4, c5)) Source # | |
(Static c1, Static c2, Static c3, Static c4, Static c5, Static c6, Typeable c1, Typeable c2, Typeable c3, Typeable c4, Typeable c5, Typeable c6, (c1, c2, c3, c4, c5, c6)) => Static (c1, c2, c3, c4, c5, c6) Source # | |
Defined in Control.Distributed.Closure Methods closureDict :: Closure (Dict (c1, c2, c3, c4, c5, c6)) Source # |