一些输入:
module error where
open import Data.Nat as ℕ
open import Level
open import Data.Vec
open import Data.Vec.N-ary
此函数从类型向量和结果类型构造函数类型:
N-Ary-from-Vec : {α γ : Level} {l : ℕ} -> Vec (Set α) l -> Set γ -> Set (N-ary-level α γ l)
N-Ary-from-Vec [] Z = Z
N-Ary-from-Vec (X ∷ Xs) Z = X -> N-Ary-from-Vec Xs Z
这是来自Arity-Generic Datatype-Generic Programming论文的两个组合器:
v∀⇒ : {n : ℕ} {α β : Level} {A : Set α}
-> (Vec A n -> Set β)
-> Set (N-ary-level α β n)
v∀⇒ {0} B = B []
v∀⇒ {ℕ.suc n} B = ∀ {x} -> v∀⇒ (λ xs -> B (x ∷ xs))
vλ⇒ : {n : ℕ} {α β : Level} {A : Set α} {B : Vec A n -> Set β}
-> ((xs : Vec A n) -> B xs)
-> v∀⇒ B
vλ⇒ {0} f = f []
vλ⇒ {ℕ.suc n} f = λ {x} -> vλ⇒ (λ xs -> f (x ∷ xs))
一些有效的定义:
ok₁ : {α γ : Level} {Z : Set γ} {l : ℕ}
-> (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs Z
-> N-Ary-from-Vec Xs Z
ok₁ = {!!}
ok₁' : {α γ : Level} {Z : Set γ}
-> (l : ℕ)
-> v∀⇒ (λ (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs Z
-> N-Ary-from-Vec Xs Z)
ok₁' l = vλ⇒ {l} ok₁
ok₂ : {α γ : Level} {Z : Set γ} {l : ℕ}
-> (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs (N-Ary-from-Vec Xs Z)
ok₂ = {!!}
ok₂' : {α γ : Level} {Z : Set γ}
-> (l : ℕ)
-> v∀⇒ (λ (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs (N-Ary-from-Vec Xs Z))
ok₂' l = vλ⇒ {l} ok₂
甚至:
ok₃ : {α γ : Level} {Z : Set γ} {l : ℕ}
-> (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs Z
-> N-Ary-from-Vec Xs (N-Ary-from-Vec Xs Z)
ok₃ = {!!}
ok₃' : {α γ : Level} {Z : Set γ}
-> (l : ℕ)
-> {x1 x2 x3 : Set α}
-> N-Ary-from-Vec (x1 ∷ x2 ∷ x3 ∷ []) Z
-> N-Ary-from-Vec (x1 ∷ x2 ∷ x3 ∷ []) (N-Ary-from-Vec (x1 ∷ x2 ∷ x3 ∷ []) Z)
ok₃' l = vλ⇒ {3} ok₃
但这不是类似的问题:
error' : {α γ : Level} {Z : Set γ}
-> (l : ℕ)
-> v∀⇒ (λ (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs Z
-> N-Ary-from-Vec Xs (N-Ary-from-Vec Xs Z))
error' l = vλ⇒ {l} ok₃
错误:
N-ary-level .α (_γ_183 l) l != .γ of type Level
when checking that the expression vλ⇒ {l} ok₃ has type
v∀⇒
(λ Xs →
N-Ary-from-Vec Xs .Z → N-Ary-from-Vec Xs (N-Ary-from-Vec Xs .Z))
有什么问题?
答案 0 :(得分:2)
没有问题,你写的代码实际上是有效的。看起来旧版本的Agda无法接受它(11月的开发版本确实如此),但它在当前的开发版本中运行良好。
似乎统一无法弄清楚究竟发生了什么,所以如果您愿意帮助它,即使在旧版本中也可以进行类型检查:
error' : {α γ : Level} {Z : Set γ}
-> (l : ℕ)
-> v∀⇒ (λ (Xs : Vec (Set α) l)
-> N-Ary-from-Vec Xs Z
-> N-Ary-from-Vec Xs (N-Ary-from-Vec Xs Z))
error' {_} {γ} l = vλ⇒ {l} (ok₃ {_} {γ})