模式匹配中变量的别名

时间:2018-11-11 18:03:17

标签: ocaml

我经常有类似于以下内容的内容(树的标准类型定义):

match tree with
    | Branch(v, Branch(vl, tll, tlr), _) = f Branch(vl, tll, tlr)

在其他语言中,可以执行以下操作:

match tree with
    | Branch(v, tl@Branch(_, _, _), _) = f tl

OCaml有类似的东西吗?

1 个答案:

答案 0 :(得分:1)

这是通过OCaml中的as关键字完成的:

match tree with
| Branch(v, (Branch(_, _, _) as tl), _) = f tl
相关问题