为什么Ocaml中的"ref None"值受限制?

Che*_*hah 3 polymorphism ocaml

值限制规则表明,只有当表达式的右侧在语法上是一个值时,才会发生泛化.

我不明白为什么let r = ref None价值受限?ref (Some 2)一个价值怎么样而ref None不是?

None是否像一个类型构造函数的情况?None不是一个价值?在我看来,这None是一个多态值.有多态值这样的东西吗?

在我看来,当与多个多态实体(如id id或)进行某种交互时会发生价值限制ref None.

我是OCaml做自学的初学者.任何帮助表示赞赏.

And*_*erg 6

可变状态不能是多态的.ref case是首先存在价值限制的原因.考虑:

let r = ref None in     (* consider this was r : 'a option ref *)
r := Some "boo";        (* then this would be well-typed *)
unSome (!r) + 1         (* and this would be well-typed as well -- BOOM! *)
Run Code Online (Sandbox Code Playgroud)

unSome是帮助者的地方:

let unSome = function Some x -> x | None -> raise Not_found
Run Code Online (Sandbox Code Playgroud)