我是Idris的初学者,我正在尝试编写一个使用Vect n Type
并返回{a : Vect n Type} -> type_1 -> ... -> type_n -> HVect (reverse a)
的函数。我已经将其类型检查下来,直到最后的递归步骤,在该步骤中,由于rewrite__impl
函数卡在类型中而使它失败。到目前为止,这是代码:
total funcGenerator : (Vect n Type) -> Type -> Type
funcGenerator [] out = out
funcGenerator (x::xs) out = x -> funcGenerator xs out
-- Reverse first argument, append second argument to it
total pileOn : Vect n Type -> Vect k Type -> Vect (plus n k) Type
pileOn [] y = y
pileOn {n=S len} {k} (x::xs) y = rewrite plusSuccRightSucc len k in
pileOn xs (x::y)
fetchArgsReverse : {h : Vect m Type} -> (b : Vect n Type) ->
HVect h -> funcGenerator (HVect (pileOn b h))
fetchArgsReverse [x] y = (\p => p::y)
fetchArgsReverse {n=S len} {m} (x::xs) y = (\p => fetchArgsReverse xs (p::y))
类型检查器抱怨如下:
|
| fetchArgsReverse {n=S len} {m} (x::xs) y = (\p => fetchArgsReverse xs (p::y))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When checking right hand side of fetchArgsReverse with expected type
funcGenerator (x::xs) (HVect (pileOn (x::xs) h))
Type mismatch between
funcGenerator xs (HVect (pileOn xs (x::h)))
(Type of fetchArgsReverse xs (p::y))
and
funcGenerator xs
(HVect (rewrite__impl (\replaced => Vect replaced Type)
(plusSuccRightSucc len m) (pileOn xs (x::h))))
(Expected Type)
(我增加了一些间距。)
该rewrite__impl
以预期的类型如何处理?我该如何解决这个问题?如果没有重写,pileOn
函数将无法正常工作。