Auto找不到它应该能够找到的值

时间:2017-11-02 13:13:05

标签: idris

为什么I会混淆自动?删除它会使一切正常。

module Main
import Data.Vect

%default total

data LessThan : String -> String -> Type where
    D : (x < x' = True) -> LessThan x x'
    I : LessThan x x' -> LessThan x' x'' -> LessThan x x'' -- Deleting this line fixes the error

data OrderedStringVect : Vect n String -> Type where
    Nil : OrderedStringVect []
    OAddF : (x : String) -> OrderedStringVect [] -> OrderedStringVect [x] -- Adding the first element does not require a LT from
    OAddO : (x : String) -> OrderedStringVect (x'::xs) -> {auto p : LessThan x x'} -> OrderedStringVect (x :: x' :: xs) -- Adding another element does

data InsertProof : String -> Vect n String -> Type where
    IPF : InsertProof n [] -- There is no first element
    IPH : LessThan n n' -> InsertProof n (n' :: ns) -- Less the the first element
    IPL : LessThan n' n -> InsertProof n ns -> InsertProof n (n' :: ns) -- Greater than the first element
    -- Eq is not allowed

insertT : (n : String) -> (ns : Vect m String) -> {auto p : InsertProof n ns} -> Vect (S m) String
insertT {p = IPF} n [] = n :: []
insertT {p = IPH _} n (n'::ns) = n :: n' :: ns
insertT {p = IPL _ _} n (n'::ns) = n' :: insertT n ns

(::) : (n : String) -> OrderedStringVect ns -> {auto p : InsertProof n ns} -> OrderedStringVect (insertT {p=p} n ns)
(::) {p = IPF} n Nil = OAddF n Nil
(::) {p = IPH _} n (OAddF n' []) = OAddO n (OAddF n' [])
(::) {p = IPH _} n (OAddO n' ns) = OAddO n (OAddO n' ns)
(::) {p = IPL _ IPF} n (OAddF n' Nil) = OAddO n' (OAddF n Nil)
(::) {p = IPL _ (IPH _)} n (OAddO n' ns) = OAddO n' (OAddO n ns)
(::) {p = IPL _ (IPL _ _)} n (OAddO n' ns) = OAddO n' (n :: ns)

test : with Main ["foo", "bar", "biz"] = ["bar", "biz", "foo"] -- Prove order does not matter
test = Refl

错误:

Type checking ./main7.idr
main7.idr:32:58-60:When checking right hand side of Main.:: with expected type
        OrderedStringVect (insertT n (n' :: x' :: xs))

When checking argument p to Main.:::
        Can't find a value of type
                InsertProof n (x' :: xs)
main7.idr:34:6:When checking type of Main.test:
Can't disambiguate name: Prelude.List.::, Main.::, Prelude.Stream.::, Data.Vect.::

编辑:我已经决定做一些完全不同的事情,所以我不再需要答案,但仍然想知道。

0 个答案:

没有答案