I'm trying to make an Idris function of type (j : Nat) -> {auto p : So (j < n)} -> Fin n
to convert a Nat
into a Fin n
. To get the Z
case to work (and output FZ
), I'm trying to prove that a proof of 0 < n
is sufficient to be able to make FZ : Fin n
. But I can't work out how to do this.
I'm open to making a completely different function, as long as it can convert Nat
values into Fin n
values (where they exist). My goal is to have some other function that can convert any Nat
into a Mod n
value, so that, for example, 15 : Nat
is mapped to 3 : Mod 4
. My Mod
type currently has a single constructor, mkMod : Fin n -> Mod n
.
After learning about
LT : Nat -> Nat -> Type
, I took a different approach. I started with the declaration:. Case-splitting on
n
, then onp
in then = Z
case resulted in:, which is essentially the proof I was asking for. From there, I case-split on
j
and filled the zero case, leaving:. I wanted to fill
?natToFin_rhs_3
withFS (natToFin j)
, but the type checker wasn't letting me. However, after a case split onp
, it was fine:Finally, I added
total
, and it all checked out.The only problem now is that Idris can't seem to find
LT
proofs automatically. This is what happens:Is there any way to fix that?