1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Documentation for Free.

This commit is contained in:
Rob Rix 2015-10-02 13:54:39 -04:00
parent ad3d4b6c3f
commit e63ccff83f

View File

@ -1,3 +1,10 @@
/// The free monad over `Syntax`.
///
/// This is free in the sense of unconstrained rather than zero-cost; its the monad obtained by taking a functor (in this case `Syntax`) and adding the minimum necessary details (the `Pure` case) to satisfy the monad laws.
///
/// `Syntax` is a non-recursive type parameterized by the type of its child nodes. Instantiating it to `Free` makes it recursive through the `Roll` case, and allows it to wrap values of type `B` through the `Pure` case.
///
/// In Doubt, this allows us to represent diffs as values of the `Free` monad obtained from `Syntax`, injecting `Patch` into the tree; or otherwise put, a diff is a tree of mutually-recursive `Free.Roll`/`Syntax` nodes with `Pure` nodes injecting the actual changes.
public enum Free<A, B> {
case Pure(B)
indirect case Roll(Syntax<Free, A>)