// since typechecking is usually syntax-directed, we can implement a typechecker as a recognizer ometa LittleTypechecker { typecheck = term:t spaces end -> t, term = "0" -> "Int" | "1" -> "Int" | "true" -> "Bool" | "false" -> "Bool" | "isZero" term:t ?(t == "Int") -> "Bool" | "if" term:t1 "then" term:t2 "else" term:t3 ?(t1 == "Bool") ?(t2 == t3) -> t2 } program = " if isZero 1 then if true then 0 else 1 else 1 " LittleTypechecker.matchAll(program, "typecheck")