Consider the following function
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)
Trying to compile, I get the following error:
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)
when calling recurvise tryMove
. If I explicitly convey {prf}
, as in
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)
It compiles correctly.
Why can't Idris automatically detect evidence at the inductive step, while he is able to do this with a normal function call?
EDIT:
here is the full meaning: https://gist.github.com/marcosh/d51479ea08e8522560713fd1e5ca9624
source
share