Idris:是否可以使用“重写”重写所有函数;加上;使用;案例;而不是",;有“吗?”?如果没有,你能举个反例吗?

Idris:是否可以使用“重写”重写所有函数;加上;使用;案例;而不是",;有“吗?”?如果没有,你能举个反例吗?,idris,Idris,在Idris中,是否可以使用“”将所有函数重写为使用“case”而不是“with” 如果没有,你能举个反例吗?不可能。当您使用与进行模式匹配时,上下文中的类型将使用从匹配的构造函数中提取的信息进行更新案例不会导致此类更新 例如,以下内容适用于with,但不适用于case: import Data.So -- here (n == 10) in the goal type is rewritten to True or False -- after the match maybeTen : (n

在Idris中,是否可以使用“”将所有函数重写为使用“case”而不是“with”


如果没有,你能举个反例吗?

不可能。当您使用
进行模式匹配时,上下文中的类型将使用从匹配的构造函数中提取的信息进行更新<代码>案例
不会导致此类更新

例如,以下内容适用于
with
,但不适用于
case

import Data.So

-- here (n == 10) in the goal type is rewritten to True or False
-- after the match
maybeTen : (n : Nat) -> Maybe (So (n == 10))
maybeTen n with (n == 10)
  maybeTen n | False = Nothing
  maybeTen n | True  = Just Oh

-- Here the context knows nothing about the result of (n == 10)
-- after the "case" match, so we can't fill in the rhs
maybeTen' : (n : Nat) -> Maybe (So (n == 10))
maybeTen' n = case (n == 10) of
  True  => ?a 
  False => ?b

所以基本上,
with
是一种
case
,它与类型级别的联系比simple
case
更紧密。非常笼统地说,IIRC
with
desugas是一个新的顶级定义,与父函数相比,它有额外的参数,基本上是函数定义强制/更新参数模式中的所有类型依赖关系。因此,这表明不可能有多个
with
-s。对吗?例如,同时n==10和n==9,这有意义吗?您可以使用任意数量的
-s(但在Idris中,一次一个,在Agda中,我们可以使用单个
进行任意数量的介绍,这很方便)。看见这也不是一个问题,
n==10
n==9
不能同时成立;在这种情况下,你可以推导出一个矛盾,即。E这是我们告诉Idris案例分支无法访问的方式。