1

いくつかの入力:

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 ペーパーの 2 つのコンビネータです。

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))

どうしたの?

4

1 に答える 1