我决定查看FParsec,并尝试为λ表达式编写解析器.事实证明,渴望使递归解析变得困难.我怎么解决这个问题?
码:
open FParsec
type ?Expr =
| Variable of char
| Application of ?Expr * ?Expr
| Lambda of char * ?Expr
let rec FV = function
| Variable v -> Set.singleton v
| Application (f, x) -> FV f + FV x
| Lambda (x, m) -> FV m - Set.singleton x
let ?0 = FV >> (=) Set.empty
let apply f p =
parse
{ let! v = p
return f v }
let ? e = …Run Code Online (Sandbox Code Playgroud)