是,在大括号{}
的论据是隐含的,他们只需要提供或匹配,如果AGDA琢磨不出来。有必要指定它们,因为依赖类型需要引用它们依赖的值,但是一直拖动它们会使代码非常笨重。
表达式cong f refl = refl
与显式参数(A → B
)和(m ≡ n
)匹配。如果你想匹配隐含的参数,你需要把匹配表达式放在{}
,但这里没有必要这样做。然后在右侧,确实是使用refl
构建(f m ≡ f n
),并且它“有魔力”。 Agda有一个内置的公理,证明这是真实的。该公理类似(但强于)J
-axiom - 归纳公理:如果C : (x y : A) → (x ≡ y) → Set
对于C x x refl
为真,则任何x y : A
和p : x ≡ y
也是如此。
J : forall {A : Set} {C : (x y : A) → (x ≡ y) → Set} →
(c : ∀ x → C x x refl) →
(x y : A) → (p : x ≡ y) → C x y p
-- this really is an axiom, but in Agda there is a stronger built-in,
-- which can be used to prove this
J c x .x refl = c x -- this _looks_ to only mean x ≡ x
-- but Agda's built-in extends this proof to all cases
-- for which x ≡ y can be constructed - that's the point
-- of having induction
cong : ∀ { a b} { A : Set a } { B : Set b }
(f : A → B) {m n} → m ≡ n → f m ≡ f n
cong f {x} {y} p = J {C = \x y p → f x ≡ f y} -- the type of equality
-- of function results
(\_ → refl) -- f x ≡ f x is true indeed
x y p
(在最后一行我们:符合明确的论点f
和p
,也隐含参数m=x
和n=y
然后我们通过J
一个隐含参数,但它不是第一个位置隐含的,所以我们。告诉agda它在定义中是C
- 如果不这样做,Agda将不会看到refl
在\_ → refl
中的含义
您在'm≡n'上进行模式匹配。 'refl'是'_≡_'类型的唯一构造函数,它只匹配语法上相同的表达式,即两个表达式需要表示完全相同的语法树。由此可见,“f”的应用也产生相同的语法树。 – 2014-11-23 18:04:36
相同的语法树,它可以归一化到同一个语义?你可以添加这个答案,以便我可以将它标记为 – nicolas 2014-11-23 19:33:07
在'9:https://www.youtube.com/watch?v=eVTc0zaS_hk&index=3 – nicolas 2014-12-03 18:17:54