1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00

Add a constructor annotating terms into Cofrees.

This commit is contained in:
Rob Rix 2015-10-14 10:39:21 -04:00
parent 961e9ae7d7
commit c13023b85b

View File

@ -16,6 +16,11 @@ public enum Cofree<A, B> {
}
/// Recursively copies a `Fix<A>` into a `Cofree<A, B>` with a function assigning `B` for every `Fix<A>`.
public init(_ fix: Fix<A>, _ annotate: Fix<A> -> B) {
self = Cofree<A, Fix<A>>.coiterate { $0.out } (fix).map(annotate)
}
public static func coiterate(annotate: B -> Syntax<B, A>)(_ seed: B) -> Cofree {
return .Unroll(seed, annotate(seed).map(coiterate(annotate)))
}