Not the same as the Haskell as-pattern, but you can get rid of the second switch statement with a nested template like this:
var description: String {
switch self {
case .Int: return "int"
case .Fun(.Fun(let p, let q), let r): return "(\(Type.Fun(p, q))) -> \(r)"
case .Fun(let p, let r): return "\(p) -> \(r)"
}
}
or by reordering cases:
var description: String {
switch self {
case .Int: return "int"
case .Fun(.Int, let r): return "int -> \(r)"
case .Fun(let p, let r): return "(\(p)) -> \(r)"
}
}
source
share