Typ Getriebene Entwicklung mit Idris präsentiert diese Übung:definieren Gleichheit von Listen Funktion
same_cons : {xs : List a} -> {ys : List a} -> xs = ys -> x :: xs = x :: ys
Allerdings habe ich versucht, es zu implementieren über:
data EqList : (xs : List a) -> (ys : List a) -> Type where
Same : (xs: List a) -> EqList xs xs
sameS : (xs : List a) -> (ys : List a) -> (x: a) -> (eq : EqList xs ys) -> EqList (x :: xs) (x :: ys)
sameS xs xs x (Same xs) = Same (x :: xs)
same_cons : {xs : List a} -> {ys : List a} -> (eq : EqList xs ys) -> EqList (x :: xs) (x :: ys)
same_cons {xs} {ys} eq = sameS xs ys _ eq
ich die x
in EqList (x :: xs) (x :: ys)
gefolgert, weil ich m verwirrt, wie man x
erhält, wenn xs
und ys
leer sind.
Auch die oben kompiliert, aber es scheiterte, als ich versuchte, es zu nennen:
*Exercises> same_cons (Same [1,2,3])
(input):Can't infer argument x to same_cons