Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Delta delta where
- data NoChange a = NoChange
- newtype Replace a = Replace a
- data DeltaList a = Append [a]
- data DeltaSet1 a
- data DeltaSet a
- mkDeltaSet :: Ord a => Set a -> Set a -> DeltaSet a
- deltaSetToList :: DeltaSet a -> [ DeltaSet1 a]
- deltaSetFromList :: Ord a => [ DeltaSet1 a] -> DeltaSet a
- data Embedding da db
-
class
Semigroupoid
(c :: k -> k ->
Type
)
where
- o :: forall (j :: k) (k1 :: k) (i :: k). c j k1 -> c i j -> c i k1
-
data
Embedding'
da db
where
- Embedding' :: ( Delta da, Delta db, a ~ Base da, b ~ Base db) => {..} -> Embedding' da db
- mkEmbedding :: Embedding' da db -> Embedding da db
- fromEmbedding :: ( Delta da, Delta db) => Embedding da db -> Embedding' da db
- pair :: Embedding da1 db1 -> Embedding da2 db2 -> Embedding (da1, da2) (db1, db2)
- liftUpdates :: Delta da => Embedding da db -> [da] -> Base da -> ( Base db, [db])
- replaceFromApply :: ( Delta da, a ~ Base da) => Embedding' da ( Replace a)
- inject :: Embedding da db -> Base da -> Machine da db
- project :: Embedding da db -> Base db -> Either SomeException ( Base da, Machine da db)
- data Machine da db = Machine { }
- idle :: Delta da => Base da -> Machine da da
- pairMachine :: Machine da1 db1 -> Machine da2 db2 -> Machine (da1, da2) (db1, db2)
- fromState :: Delta db => (( Base da, da) -> ( Base db, s) -> (db, s)) -> ( Base db, s) -> Machine da db
Synopsis
Delta encodings.
The type constraint
Delta
delta
means that the type
delta
is a delta encoding of the corresponding base type
Base
delta
.
Delta encodings can be transformed into each other using an
Embedding
.
Delta encodings
class Delta delta where Source #
Type class for delta encodings.
type Base delta :: Type Source #
Base type for which
delta
represents a delta encoding.
This is implemented as a type family, so that we can have
multiple delta encodings for the same base type.
FIXME: Better name for
Base
? It's sooo generic.
Pier, dock, ground, anchor, site, …
Instances
Delta delta => Delta [delta] Source # |
A list of deltas can be applied like a single delta.
This overloading of
Order is important: The
apply [] = id apply (d1 <> d2) = apply d1 . apply d2 |
Delta delta => Delta ( Maybe delta) Source # |
A delta can be optionally applied. |
Delta delta => Delta ( NonEmpty delta) Source # |
For convenience, a nonempty list of deltas can be applied like a list of deltas. |
Ord a => Delta ( DeltaSet a) Source # | |
Ord a => Delta ( DeltaSet1 a) Source # | |
Delta ( DeltaList a) Source # | |
Delta ( Replace a) Source # | |
Delta ( NoChange a) Source # | |
Delta ( DeltaTable row) Source # | |
Defined in Data.Table type Base ( DeltaTable row) Source # apply :: DeltaTable row -> Base ( DeltaTable row) -> Base ( DeltaTable row) Source # |
|
( Delta d1, Delta d2) => Delta (d1, d2) Source # |
A pair of deltas represents a delta for a pair. |
( Ord key, Delta da) => Delta ( DeltaMap key da) Source # | |
key ~ Int => Delta ( DeltaDB key row) Source # | |
( Ord node, Semigroup edge) => Delta ( DeltaChain node edge) Source # | |
Defined in Data.Chain type Base ( DeltaChain node edge) Source # apply :: DeltaChain node edge -> Base ( DeltaChain node edge) -> Base ( DeltaChain node edge) Source # |
|
( Delta d1, Delta d2, Delta d3) => Delta (d1, d2, d3) Source # |
A triple of deltas represents a delta for a triple. |
( Delta d1, Delta d2, Delta d3, Delta d4) => Delta (d1, d2, d3, d4) Source # |
A 4-tuple of deltas represents a delta for a 4-tuple. |
Trivial delta encoding for the type
a
that admits no change at all.
Instances
Eq ( NoChange a) Source # | |
Ord ( NoChange a) Source # | |
Defined in Data.Delta compare :: NoChange a -> NoChange a -> Ordering Source # (<) :: NoChange a -> NoChange a -> Bool Source # (<=) :: NoChange a -> NoChange a -> Bool Source # (>) :: NoChange a -> NoChange a -> Bool Source # (>=) :: NoChange a -> NoChange a -> Bool Source # |
|
Show ( NoChange a) Source # | |
Delta ( NoChange a) Source # | |
type Base ( NoChange a) Source # | |
Defined in Data.Delta |
Trivial delta encoding for the type
a
that replaces the value wholesale.
Replace a |
Instances
Eq a => Eq ( Replace a) Source # | |
Ord a => Ord ( Replace a) Source # | |
Defined in Data.Delta |
|
Show a => Show ( Replace a) Source # | |
Semigroup ( Replace a) Source # |
Combine replacements. The first argument takes precedence.
In this way,
|
Delta ( Replace a) Source # | |
type Base ( Replace a) Source # | |
Defined in Data.Delta |
Delta encoding for lists where a list of elements is prepended.
Append [a] |
Instances
Eq a => Eq ( DeltaList a) Source # | |
Ord a => Ord ( DeltaList a) Source # | |
Defined in Data.Delta compare :: DeltaList a -> DeltaList a -> Ordering Source # (<) :: DeltaList a -> DeltaList a -> Bool Source # (<=) :: DeltaList a -> DeltaList a -> Bool Source # (>) :: DeltaList a -> DeltaList a -> Bool Source # (>=) :: DeltaList a -> DeltaList a -> Bool Source # |
|
Show a => Show ( DeltaList a) Source # | |
Delta ( DeltaList a) Source # | |
type Base ( DeltaList a) Source # | |
Defined in Data.Delta |
Delta encoding for
Set
where a single element is deleted or added.
Instances
Eq a => Eq ( DeltaSet1 a) Source # | |
Ord a => Ord ( DeltaSet1 a) Source # | |
Defined in Data.Delta compare :: DeltaSet1 a -> DeltaSet1 a -> Ordering Source # (<) :: DeltaSet1 a -> DeltaSet1 a -> Bool Source # (<=) :: DeltaSet1 a -> DeltaSet1 a -> Bool Source # (>) :: DeltaSet1 a -> DeltaSet1 a -> Bool Source # (>=) :: DeltaSet1 a -> DeltaSet1 a -> Bool Source # |
|
Show a => Show ( DeltaSet1 a) Source # | |
Ord a => Delta ( DeltaSet1 a) Source # | |
type Base ( DeltaSet1 a) Source # | |
Defined in Data.Delta |
Delta encoding for a
Set
where
collections of elements are inserted or deleted.
mkDeltaSet :: Ord a => Set a -> Set a -> DeltaSet a Source #
Delta to get from the second argument to the first argument.
deltaSetToList :: DeltaSet a -> [ DeltaSet1 a] Source #
Embedding of types and delta encodings
An
Embedding
da db
embeds one type and its delta encoding
da
into another type and its delta encoding
db
.
For reasons of efficiency,
Embedding
is an abstract type.
It is constructed using the
Embedding'
type, which has
three components.
-
write
embeds values from the typea = Base da
into the typeb = Base bd
. -
load
attempts to retrieve the value of typea
from the typeb
, but does not necessarily succeed. -
update
maps a delta encodingda
to a delta encodingdb
. For this mapping, the value of typea
and a corresponding value of typeb
are provided; the delta encodings of typesda
anddb
are relative to these values.
The embedding of one type into the other is characterized by the following properties:
-
The embedding need not be surjective : The type
b
may contain many values that do not correspond to a value of typea
. Hence,load
has anEither
result. (See Note [EitherSomeException] for the choice of exception type.) However, retrieving a written value always succeeds, we haveload . write = Right
-
The embedding is redundant : The type
b
may contain multiple values that correspond to one and the samea
. This is why theupdate
function expects the typeb
as argument, so that the right delta encoding can be computed. Put differently, we often havewrite a ≠ b where Right a = load b
-
The embedding of delta encoding commutes with
apply
. We haveJust (apply da a) = load (apply (update a b da) b) where Right a = load b
However, since the embedding is redundant, we often have
apply (update a (write a) da) (write a) ≠ write (apply da a)
Embedding
with efficient composition
o
.
To construct an embedding, use
mkEmbedding
.
class Semigroupoid (c :: k -> k -> Type ) where Source #
Instances
Semigroupoid ( Coercion :: k -> k -> Type ) | |
Semigroupoid ( (:~:) :: k -> k -> Type ) | |
Semigroupoid ( (:~~:) :: k -> k -> Type ) | |
Category k2 => Semigroupoid ( WrappedCategory k2 :: k1 -> k1 -> Type ) | |
Defined in Data.Semigroupoid o :: forall (j :: k) (k10 :: k) (i :: k). WrappedCategory k2 j k10 -> WrappedCategory k2 i j -> WrappedCategory k2 i k10 Source # |
|
Semigroup m => Semigroupoid ( Semi m :: k -> k -> Type ) | |
Semigroupoid (,) |
http://en.wikipedia.org/wiki/Band_(mathematics)#Rectangular_bands |
Defined in Data.Semigroupoid |
|
Semigroupoid Op | |
Semigroupoid Machine Source # |
Composition of
|
Semigroupoid Embedding Source # |
Efficient composition of
|
Bind m => Semigroupoid ( Kleisli m :: Type -> Type -> Type ) | |
Semigroupoid ( Const :: Type -> Type -> Type ) | |
Semigroupoid ( Tagged :: Type -> Type -> Type ) | |
Semigroupoid ((->) :: Type -> Type -> Type ) | |
Defined in Data.Semigroupoid |
|
Extend w => Semigroupoid ( Cokleisli w :: Type -> Type -> Type ) | |
data Embedding' da db where Source #
Specification of an embedding of a type
a
with delta encoding
da
into the type
b
with delta encoding
db
.
See
the discussion of
Embedding
for a more detailed description.
Embedding' | |
|
mkEmbedding :: Embedding' da db -> Embedding da db Source #
Construct
Embedding
with efficient composition
fromEmbedding :: ( Delta da, Delta db) => Embedding da db -> Embedding' da db Source #
pair :: Embedding da1 db1 -> Embedding da2 db2 -> Embedding (da1, da2) (db1, db2) Source #
A pair of
Embedding
s gives an embedding of pairs.
:: Delta da | |
=> Embedding da db | |
-> [da] |
List of deltas to apply. The
|
-> Base da |
Base value to apply the deltas to. |
-> ( Base db, [db]) |
(Final base value, updates that were applied (
|
Lift a sequence of updates through an
Embedding
.
replaceFromApply :: ( Delta da, a ~ Base da) => Embedding' da ( Replace a) Source #
Internal
Strict pair. If a value of this type is in WHNF, so are the two components. data StrictPair a b = !a :*: !b infixr 1 :*:
A state machine that maps deltas to deltas.
This machine always carries a state of type
Base
db
around.