2017-04-04 4 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があります。これらは2つの異なるタイプです。

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)