diff --git a/prototype/Doubt/Cofree.swift b/prototype/Doubt/Cofree.swift index e774e8a46..54fe26f4f 100644 --- a/prototype/Doubt/Cofree.swift +++ b/prototype/Doubt/Cofree.swift @@ -16,6 +16,11 @@ public enum Cofree { } + /// Recursively copies a `Fix` into a `Cofree` with a function assigning `B` for every `Fix`. + public init(_ fix: Fix, _ annotate: Fix -> B) { + self = Cofree>.coiterate { $0.out } (fix).map(annotate) + } + public static func coiterate(annotate: B -> Syntax)(_ seed: B) -> Cofree { return .Unroll(seed, annotate(seed).map(coiterate(annotate))) }