考虑以下功能
tryMove : (diskNumber : Nat) -> (from: Peg) -> (to: Peg)-> {default Oh prf: So (from /= to)} -> Disposition diskNumber -> Maybe (Disposition diskNumber)
tryMove Z from to [] = Nothing
tryMove (S k) from to (smallestDiskPosition :: restOfTheDisposition) =
map (smallestDiskPosition ::) (tryMove k from to restOfTheDisposition)
尝试编译我收到以下错误:
When checking argument prf to Hanoi.tryMove:
Type mismatch between
So True (Type of Oh)
and
So (from /= to) (Expected type)
Specifically:
Type mismatch between
True
and
not (Hanoi.Peg implementation of Prelude.Interfaces.Eq, method == from to)
关于tryMove
的重新调用。
如果我在
{prf}
tryMove : (diskNumber : Nat) -> (from: Peg) -> (to: Peg)-> {default Oh prf: So (from /= to)} -> Disposition diskNumber -> Maybe (Disposition diskNumber)
tryMove Z from to [] = Nothing
tryMove (S k) from to {prf} (smallestDiskPosition :: restOfTheDisposition) =
map (smallestDiskPosition ::) (tryMove k from to {prf} restOfTheDisposition)
它编译正确。
为什么Idris无法在归纳步骤中自动检测到证据,而能够在函数的正常调用中执行此操作?
编辑:
这里有一个完整的要点:https://gist.github.com/marcosh/d51479ea08e8522560713fd1e5ca9624
答案 0 :(得分:4)
您为<todo-list @items={{ items }} @rootclickme={{action rootclickme}}></todo-list>
提供默认值(Oh
),因此Idris正在尝试将prf
传递给递归调用。
Oh
的类型为Oh
,而Idris希望So True
的类型为prf
,但因为您不会破坏So (from /= to)
和to
,Idris无法知道from
的价值,这就是您看到错误消息的原因。
您可以更改签名以包含from /= to
或完全删除{auto prf: So (from /= to)}
参数,因为您实际上并未使用它,只需将其传递给递归调用而不进行任何修改。< / p>