I need some help interpreting an error message regarding implicit arguments in Idris and why a small change fixes it. This is the code:
import Data.Vect
myReverse : Vect n elem -> Vect n elem
myReverse [] = []
myReverse {n} (x :: xs)
= let result = myReverse xs ++ [x] in
?rhs
It results in this error:
When checking left hand side of myReverse:
When checking an application of Main.myReverse:
Type mismatch between
Vect (S len) elem (Type of x :: xs)
and
Vect n elem (Expected type)
Specifically:
Type mismatch between
S len
and
n
However, replacing {n}
with {n = S len}
, the code type-checks.
I thought that using
{n}
was simply meant to bring the implicitn
argument of the function into scope. Why would this result in an error?What does the error message mean? The only interpretation I can think of is that the implicit argument
n
in the type is rewritten due to pattern-matchingx::xs
intoS len
, and Idris loses information that these are the same.How does replacing it with
{n = S len}
work?