请考虑以下功能,即使实施不相关:
vectTranspose : Vect n (Fin 3) -> Vect 3 (List (Fin n))
vectTranspose {n = Z} [] = [[],[],[]]
vectTranspose {n = (S len)} (x :: xs) with (natToFin len (S len))
| Just l = let
previous = map (map weaken) (vectTranspose xs)
in updateAt x (l ::) previous
如果我尝试在REPL中计算vectTranspose
,我会按预期得到[[],[],[]]
。
但是,如果我在我的代码中添加如下所示的相等断言
emptyTest : vectTranspose [] = [[],[],[]]
emptyTest = Refl
然后我收到编译错误:
When checking right hand side of emptyTest with expected type
vectTranspose [] = [[], [], []]
Type mismatch between
[[], [], []] = [[], [], []] (Type of Refl)
and
vectTranspose [] = [[], [], []] (Expected type)
Specifically:
Type mismatch between
[[], [], []]
and
vectTranspose []
我错过了什么吗?我应该在断言中以某种方式指定[[],[],[]]
的类型吗?
答案 0 :(得分:2)
idris抱怨
的类型Specifically:
Type mismatch between
[[], [], []]
and
vectTranspose []
表示vectTranspose
仍在类型中且尚未解析。如果vectTranspose不是完全的,实际上它不是:
VecTest.vectTranspose is possibly not total due to:
with block in VecTest.vectTranspose, which is not total as there are missing cases
这是因为您没有涵盖所有Maybe
个案例。
一个简单的解决方案可能是创建一个小辅助函数:
total
natToFin': (n: Nat) -> Fin (S n)
natToFin' Z = FZ
natToFin' (S k) = FS (natToFin' k)
total
vectTranspose : Vect n (Fin 3) -> Vect 3 (List (Fin n))
vectTranspose {n = Z} [] = [[], [], []]
vectTranspose {n = (S len)} (x :: xs) with (natToFin' len)
vectTranspose {n = (S len)} (x :: xs) | l = let
previous = map (map weaken) (vectTranspose xs)
in updateAt x (l ::) previous