2015-10-14 20:52:25 +03:00
|
|
|
/// The type of terms.
|
|
|
|
public protocol TermType {
|
|
|
|
typealias LeafType
|
|
|
|
|
|
|
|
var out: Syntax<Self, LeafType> { get }
|
|
|
|
}
|
2015-10-14 20:57:21 +03:00
|
|
|
|
|
|
|
|
2015-10-15 01:42:20 +03:00
|
|
|
extension TermType {
|
|
|
|
public func cata<Result>(transform: Syntax<Result, LeafType> -> Result) -> Result {
|
|
|
|
return self |> ({ $0.out } >>> { $0.map { $0.cata(transform) } } >>> transform)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-14 20:57:21 +03:00
|
|
|
extension Fix: TermType {}
|
2015-10-14 21:05:43 +03:00
|
|
|
|
|
|
|
extension Cofree: TermType {
|
|
|
|
public var out: Syntax<Cofree, A> {
|
|
|
|
return unwrap
|
|
|
|
}
|
|
|
|
}
|
2015-10-15 01:42:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
import Prelude
|