Agda:在`with`块中没有简化类型

时间:2016-07-25 15:59:03

标签: agda

我正在努力解决this教程第23页的奖金练习,但我无法填写这个漏洞:

lem-all-filter : {A : Set}(xs : List A)(p : A -> Bool)
              -> All (satisfies p) (filter p xs)
lem-all-filter [] p = all[]
lem-all-filter (x :: xs) p with p x
... | true = {! !} :all: lem-all-filter xs p
... | false = lem-all-filter xs p

如果我输入C-c C-,那么我会收到这条消息:

Goal: isTrue (p x)
--------------------------------
xs : List .A
p  : .A -> Bool
x  : .A
.A : Set

但我希望目标的类型为True,因为p xtrueisTrue true = True。我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

当您在p x上进行模式匹配时,p x会被重写为上下文中的模式,但是这个漏洞在重写时不在上下文中:它出现在后面,因此{{1在其类型中不会被重写。您可以使用本文后面所述的检查习惯用法(现在弃用inspect on steroids)来记住p x等于p x,但您也可以执行以下操作:

true

在此,您在上下文中明确地向lem-all-filter : {A : Set}(xs : List A)(p : A -> Bool) -> All (satisfies p) (filter p xs) lem-all-filter [] p = all[] lem-all-filter (x :: xs) p with p x | λ (y : isTrue (p x)) -> y :all: lem-all-filter xs p ... | true | onTrue = onTrue _ ... | false | onTrue = lem-all-filter xs p 引入了参数的类型,因此当:all:被重写为p x时,true的类型会减少为{{ 1}}根据需要。