(这是多态变体和 let%bind 类型错误的扩展/蒸馏)
考虑以下代码:
版本 1:
let x : [> `Error1 ] = (`Error1 : [> `Error1 ])
let y : [> `Error1 | `Error2 ] = x
版本 2:
let x : [> `Error1 ] = (`Error1 : [ `Error1 ])
let y : [> `Error1 | `Error2 ] = x
版本 1 类型检查,但版本 2 失败(我正在使用 4.09.0 编译):
File "test.ml", line 2, characters 33-34:
2 | let y : [> `Error1 | `Error2 ] = x
^
Error: This expression has type [ `Error1 ]
but an expression was expected of type [> `Error1 | `Error2 ]
The first variant type does not allow tag(s) `Error2
请注意,此错误发生在 的定义中y
,但两种情况下的签名x
相同!怎么y
能看到里面的定义x
呢?是否有x
比其签名更多的类型检查信息?