blob: c53877940b148e9333837d7aae99624f0c7b8b13 [file] [log] [blame]
// RUN: not %target-swift-frontend %s -typecheck
protocol Fixpoint {
typealias Algebra : Algebraic
init(_ : Algebra)
var out: Algebra { get }}
protocol Algebraic {typealias Recur}
enum Expr<T>: Algebraic {
typealias Recur = T
case Null
func map<U>(transform: T -> U) -> Expr<U> {return .Null}
}
func out<Fix: Fixpoint>(v: Fix) -> Fix.Recur {return v.out}
func cata<T, Fix: Fixpoint where Fix.Recur == Expr<Fix>>(f: Expr<T> -> T)(_ term: Fix) -> T {
return f({ $0.map(cata(f)) }(out(term)))
}
struct Term: Fixpoint, CustomDebugStringConvertible {
typealias Algebra = Expr<Term>
var debugDescription: String {return cata(Term.toDebugString)(self)}
static func toDebugString(expression: Expr<String>) -> String {return ""}
}