【问题标题】:What is the meaning of the open record pattern?打开记录模式的含义是什么?
【发布时间】:2016-03-31 09:17:06
【问题描述】:

OCaml 有一个明确的句法结构(参见Parsetree.pattern_desc, constructor Ppat_record)来区分“打开”和“关闭”记录模式。

这似乎对模式匹配没有任何影响:

utop # type r = {repr:int; foo:int} ;;
type r = { repr : int; foo : int; } 
utop # let f = function {repr} -> repr;;
val f : r -> int =  <fun> 
utop # let g = function {repr;_} -> repr;;
val g : r -> int = <fun> 

那么它的目的是什么?这是某种 SML 遗物吗?

【问题讨论】:

    标签: pattern-matching ocaml record


    【解决方案1】:

    这只是一个语言扩展,告诉编译器您故意忽略了某些字段,以便在您忘记某个字段时收到警告。

    http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec226

    【讨论】:

      猜你喜欢
      • 2017-01-06
      • 2013-09-26
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 2017-01-23
      • 1970-01-01
      相关资源
      最近更新 更多