mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
A parse-only option is needed for parse performance tracking and the current option also includes semantic analysis.
22 lines
733 B
Swift
22 lines
733 B
Swift
// 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 ""}
|
|
}
|