2017-04-04 1 views
1

는 주어의 이해 : 은`decEq`

*section3> :module Data.Vect  
*section3> :let e = the (Vect 0 Int) [] 
*section3> :let xs = the (Vect _ _) [1,2] 

*section3> decEq xs e 
(input):1:7:When checking argument x2 to function Decidable.Equality.decEq: 
     Type mismatch between 
       Vect 0 Int (Type of e) 
     and 
       Vect 2 Integer (Expected type) 

     Specifically: 
       Type mismatch between 
         0 
       and 
         2 

Nat 인수 DecEq 서로 동일해야?

주 - https://groups.google.com/forum/#!topic/idris-lang/qgtImCLka3I에 게시 원래

+3

'VECT 0 Int'와'VECT 1 Int' :

먼저 균일 한 버전으로 위임 한 후, 자신의 길이를 확인하여 같은 요소 유형의 Vect ORS에 대한 자신의 이종 평등 결정자를 쓸 수 있습니다 'Vect n Int'와'Vect n Float'과 같은 타입이 있습니다. – gallais

답변

4

decEq균일 명제 평등을위한 것입니다 : 당신이 볼 수 있듯이

||| Decision procedures for propositional equality 
interface DecEq t where 
    ||| Decide whether two elements of `t` are propositionally equal 
    total decEq : (x1 : t) -> (x2 : t) -> Dec (x1 = x2) 

, x1x2 유형 t의 등록 상표입니다. 귀하의 경우에는 x1 : Vect 2 Integerx2 : Vect 0 Int입니다. 이들은 두 가지 유형입니다.

import Data.Vect 

vectLength : {xs : Vect n a} -> {ys : Vect m a} -> xs = ys -> n = m 
vectLength {n = n} {m = n} Refl = Refl 

decEqVect : (DecEq a) => (xs : Vect n a) -> (ys : Vect m a) -> Dec (xs = ys) 
decEqVect {n = n} {m = m} xs ys with (decEq n m) 
decEqVect xs ys | Yes Refl = decEq xs ys 
decEqVect xs ys | No notEq = No (notEq . vectLength)