2017-10-04 7 views
3
import Data.Vect 
import Data.Vect.Quantifiers 

sameKeys : Vect n (lbl, Type) -> Vect n (lbl, Type) -> Type 
sameKeys xs ys = All (uncurry (=)) (zip (map fst xs) (map fst ys)) 

g : {xs,ys : Vect n (lbl, Type)} -> sameKeys xs ys -> map (\b => fst b) xs = map (\b => fst b) ys 
g {xs = []} {ys = []} [] = Refl 
g {xs = x::xs} {ys = y::ys} (p::ps) = rewrite g ps in ?q 

を発生しません。これは私が見誤りである:イドリス・リライトは

*main> :load main.idr 
Type checking ./main.idr 
main.idr:57:3:When checking right hand side of g with expected type 
     map (\b => fst b) (x :: xs) = map (\b6 => fst b6) (y :: ys) 

rewriting 
    Data.Vect.Vect n implementation of Prelude.Functor.Functor, method map (\b => fst b) xs 
to 
    Data.Vect.Vect n implementation of Prelude.Functor.Functor, method map (\b6 => fst b6) ys 
did not change type 
    fst x :: Data.Vect.Vect n implementation of Prelude.Functor.Functor, method map (\b => fst b) xs = fst y :: Data.Vect.Vect n implementation of Prelude.Functor.Functor, method map (\b6 => fst b6) ys 
Holes: Main.g 

なぜそれを書き換えていないのですか?

答えて

2

これは、Idrisが何らかの理由で正しい暗黙の引数をgに推測することができず、代わりにコンテキスト内に新しいベクトルを導入するために起こります。

回避策として、次のように証明することをお勧めします。まず、我々は2つの引数の機能のための合同補題必要があります

total 
cong2 : {f : a -> b -> c} -> (a1 = a2) -> (b1 = b2) -> f a1 b1 = f a2 b2 
cong2 Refl Refl = Refl 

は今、元の補題の証明は簡単です:

total 
g : sameKeys xs ys -> map (\b => fst b) xs = map (\b => fst b) ys 
g {xs = []} {ys = []} x = Refl 
g {xs = x :: xs} {ys = y :: ys} (p :: ps) = cong2 p $ g ps