埃菲尔铁塔中的可拆卸通用到通用

detachable generic to generic in eiffel

我有一个 post 条件如下的特征:

checkValue (k: K): detachable V
do
...
end
ensure
some_post_condition:
    checkKey (Result)

这里是 "checkKey" 的原型:

checkKey (v: V): BOOLEAN

因为 "Result" 是 "detachable V" 的类型,我尝试将其作为参数传递给 "checkKey ",它只接受 "V" 的类型但不接受 "detachable V" ], 因此无法编译。

这是编译错误的内容:

Argument name: v
Argument position: 1
Formal argument type: Generic #1
Actual argument type: detachable Generic #1

如何将可分离的通用转换为通用?

有几种选择:

  1. checkValue 的类型从 detachable V 更改为 V
  2. checkKey 的参数类型从 V 更改为 detachable V
  3. 将后置条件更改为读取

    • 如果 Result 应始终附加

      result_attached: attached Result
      some_post_condition: checkKey (Result)
      
    • 如果Result可能是可拆卸的(在这种情况下它被认为是有效的):

      some_post_condition: attached Result implies checkKey (Result)