package diff
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=6316048a1c65fa28a0ee71fa1450d87c
sha512=07d1be5825e00f6d10e6c9d175ef7cc300dc6b8993d91004817d4dc086298798fe7d017b8024d1c1b62d35fbf091077c1fb518418c7f1039e3e071ef07db0f5a
Description
Added to opam-repository:
README
diff
An OCaml library for generating diffs of product types.
Example
type t = { foo : int; bar : string; }
[@@deriving diff]
let spec = Diff.many [
Diff.leaf ~field:Foo ~equal:Int.equal;
Diff.leaf ~field:Bar ~equal:String.equal;
]
let () =
let t0 = { foo = 1; bar = "Skolem" } in
let t1 = { foo = 1; bar = "OCaml" } in
let diff = Diff.compute t0 t1 spec in
let t0' = Diff.apply_all t0 diff in
assert (t0' = t1)Usage
The main use case of this library is to version records without having to keep a copy of each version around.
The library includes a ppx for generating field accessors from records. To use the ppx with dune, add it to the preprocessing field of your stanza:
(library
(name mylib)
...
(preprocessing (pps diff.ppx)))In order to actually compute diffs, you need to write a spec for how your record should be traversed. There are functions provided to help you do so:
leaf ~field ~equalrepresents a "terminal" node in the spec tree, i.e. the diffing algorithm should simply compare the field values and add it to the diff list if they are different.child ~field ~specrepresents an "intermediate" node in the spec tree, i.e. the diffing algorithm should recursively compute the diff of a "child" record.opt_child ~field ~specreprents an optional intermediate node in the spec tree, i.e. a child record that is optional in the parent.many specs: flattens many specs into a single one.
For more usage examples, check out example/example.ml and tests/*_test.ml.
License
This project is licensed under the MIT License.
Dev Dependencies (4)
-
odoc
with-doc -
tezt
with-test & >= "3.1.1" & < "4.0.0" -
ppx_deriving
with-test -
ocamlformat
with-dev-setup
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building diff with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 1.0.2 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure