2015-10-02 20:54:39 +03:00
|
|
|
|
/// The free monad over `Syntax`.
|
|
|
|
|
///
|
|
|
|
|
/// This is “free” in the sense of “unconstrained” rather than “zero-cost”; it’s 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.
|
2015-10-02 20:43:43 +03:00
|
|
|
|
public enum Free<A, B> {
|
|
|
|
|
case Pure(B)
|
|
|
|
|
indirect case Roll(Syntax<Free, A>)
|
|
|
|
|
}
|