Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eiffel 埃菲尔铁塔中的可拆卸通用到通用_Eiffel - Fatal编程技术网

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

Eiffel 埃菲尔铁塔中的可拆卸通用到通用,eiffel,Eiffel,我有一个具有post条件的功能,如下所示: checkValue (k: K): detachable V do ... end ensure some_post_condition: checkKey (Result) 下面是“checkKey”的原型: 由于“Result”是“detaccable V”类型,我尝试将其作为参数传递给“checkKey”,它只接受“V”类型而不接受“detaccable V”,因此它无法编译 下面是编译错误所说的: Argument name: v

我有一个具有post条件的功能,如下所示:

checkValue (k: K): detachable V
do
...
end
ensure
some_post_condition:
    checkKey (Result)
下面是“checkKey”的原型:

由于“Result”是“detaccable V”类型,我尝试将其作为参数传递给“checkKey”,它只接受“V”类型而不接受“detaccable V”,因此它无法编译

下面是编译错误所说的:

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

如何将可拆卸的通用型转换为通用型?

有几个选项:

  • checkValue
    的类型从
    detaccable V
    更改为
    V
  • checkKey
    的参数类型从
    V
    更改为
    可分离的V
  • 将后置条件更改为

    • 如果
      结果
      应始终附加

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

  • result_attached: attached Result
    some_post_condition: checkKey (Result)
    
    some_post_condition: attached Result implies checkKey (Result)