patch: Infrastructure for writing patches which act on other types.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

In this library, a patch is something which can be applied, analogous to a function, and which distinguishes returning the argument it was provided from returning something else.


[Skip to Readme]

Properties

Versions 0.0.0.0, 0.0.0.1, 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.3.1, 0.0.3.1, 0.0.3.2, 0.0.4.0, 0.0.5.0, 0.0.5.1, 0.0.5.2
Change log ChangeLog.md
Dependencies base (>=4.9 && <4.14), constraints-extras (==0.3.*), containers (==0.6.*), dependent-map (==0.3.*), dependent-sum (==0.6.*), lens (>=4.7 && <5), monoidal-containers (==0.4.0.0 || ==0.6.*), semialign (>=1 && <1.2), semigroupoids (>=4.0 && <6), these (>=0.4 && <0.9 || >=1 && <1.1), transformers (>=0.5.6.0 && <0.6), witherable (>=0.3 && <0.3.2) [details]
License BSD-3-Clause
Author Ryan Trinkle
Maintainer maintainer@obsidian.systems
Category FRP
Home page https://obsidian.systems
Bug tracker https://github.com/reflex-frp/patch/issues
Source repo head: git clone https://github.com/reflex-frp/patch
Uploaded by JohnEricson at 2020-02-06T03:15:55Z

Modules

[Index]

Manual Flags

NameDescriptionDefault
Automatic Flags
NameDescriptionDefault
split-these

Use split these/semialign packages

Enabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for patch-0.0.3.1

[back to package description]

Patch

Infrastructure for writing patches which act on other types.

A Patch type represents a kind of change made to a datastructure.

class Patch p where
  type PatchTarget p :: *
  -- | Apply the patch p a to the value a.  If no change is needed, return
  -- 'Nothing'.
  apply :: p -> PatchTarget p -> Maybe (PatchTarget p)

Patching Maps

For example, Data.Patch.Map defines the PatchMap type which can be used to patch Maps. A PatchMap represents updates to a Map that can insert, remove, or replace items in the Map. In this example, the Map is the PatchTarget and the PatchMap is the Patch. Keep in mind that there are many other possible Patches that can be applied to a Map (i.e., Map can be the PatchTarget for many different Patch instances).

PatchMap is defined as:

newtype PatchMap k v = PatchMap { unPatchMap :: Map k (Maybe v) }

The Maybe around the value is used to represent insertion/updates or deletion of the element at a given key.

Its Patch instance begins with:

instance Ord k => Patch (PatchMap k v) where
  type PatchTarget (PatchMap k v) = Map k v
  ...

When a PatchMap is applied to its PatchTarget, the following changes can occur:

There are, of course, more complicated ways of patching maps involving, for example, moving values from one key to another. You can find the code for that in Data.Patch.PatchMapWithMove. Note that the PatchTarget type associated with the PatchMapWithMove patch instance is still Map k v!