Hi all,
I'm a newcomer in the Idris world, I'm just trying to understand how all these new things work, reading the "Type Driven Development with Idris" book and experimenting with some code.
I'm now facing a problem that I can't understand. Here is an example that currently doesn't type-check:
import Data.Vect
data Rankings: Nat -> Type where
MkRankings: (count : Nat) -> Vect count String -> Rankings count
data Position: (rankings: Rankings (S maxIndex)) -> Type where
MkPosition: (pos: Fin (S maxIndex)) -> Position rankings
rankingsNames: Rankings count -> Vect count String
rankingsNames (MkRankings count names) = names
nameAtPosition: {rankings: Rankings (S maxIndex)} -> Position rankings -> String
nameAtPosition {rankings} (MkPosition pos) = let allNames = rankingsNames rankings in
index pos allNames
Please, don't stop on the usefulness of this code, it is just an example I've extracted from a more complex code I'm working.
If you try to make it compile, you can see that the last line doesn't work because of some mismatch on the maxIndex value. I can't understand why it doesn't work since a Position instance is related to the "maxIndex" value provided by the Rankings instance that defines the type itself (Position rankings).
What should I do/change in order to make this code compile?
Sorry if I didn't explained my problem quite well, I'm new to this world and I don't own very much the correct terminology.
Thank you very much!
Emanuele