Safe Haskell | Safe |
---|---|
Language | Haskell98 |
The interface for types which represent changes made to other types
Synopsis
- class Patch p where
- type PatchTarget p :: *
- apply :: p -> PatchTarget p -> Maybe (PatchTarget p)
- applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p
- composePatchFunctions :: (Patch p, Semigroup p) => (PatchTarget p -> p) -> (PatchTarget p -> p) -> PatchTarget p -> p
Documentation
A Patch
type represents a kind of change made to a datastructure.
If an instance of Patch
is also an instance of Semigroup
, it should obey
the law that applyAlways (f <> g) == applyAlways f . applyAlways g
.
type PatchTarget p :: * Source #
apply :: p -> PatchTarget p -> Maybe (PatchTarget p) Source #
Apply the patch p a
to the value a
. If no change is needed, return
Nothing
.
Instances
applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p Source #
Apply a Patch
; if it does nothing, return the original value
composePatchFunctions :: (Patch p, Semigroup p) => (PatchTarget p -> p) -> (PatchTarget p -> p) -> PatchTarget p -> p Source #
Like '(.)', but composes functions that return patches rather than functions that return new values. The Semigroup instance for patches must apply patches right-to-left, like '(.)'.