我正在努力解决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 x
是true
和isTrue true = True
。我错过了什么吗?
答案 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}}根据需要。