The first problem is superficial: you are trying to apply rewriting in the wrong place. If you have x : GE n (n + Z) , you will have to rewrite its type if you want to use it as the definition of geRefl : GE nn , so you will have to write
geRefl : GE nn geRefl {n} = rewrite plusZeroRightNeutral n in x
But it still wonโt work. The real problem is that you only want to rewrite a part like GE nn : if you just rewrite it with n + 0 = n , you will get GE (n + 0) (n + 0) , which you still cannot use using Ge n 0 : GE n (n + 0) .
What you need to do is use the fact that if a = b , then x : GE na can be turned into x' : GE nb . This is exactly what the replace function in the standard library provides:
replace : (x = y) -> P x -> P y
Using this, setting P = GE n and using Ge n 0 : GE n (n + 0) , we can write geRefl as
geRefl {n} = replace {P = GE n} (plusZeroRightNeutral n) (Ge n 0)
(note that Idris is quite capable of inferring the implicit parameter P , so it works without it, but I think in this case it clarifies what happens)
source share