I am trying to represent multi-dimensional arrays as restricted functions, and I am having a trouble with defining what seem to be a primitive function.
Here are the definitions:
Require Export Fin. Require Export PeanoNat. Inductive ispace : nat -> Type := Rect: forall d:nat, ((Fin.t d) -> nat) -> ispace d. Inductive index : nat -> Type := Idx: forall d: nat, (Fin.t d -> nat) -> index d. Inductive bound_idx : forall d, index d -> ispace d -> Prop -> Type := RectBoundIdx : forall d f_idx f_shp, bound_idx d (Idx d f_idx) (Rect d f_shp) (forall i, f_idx i < f_shp i). Inductive array : forall d (is:ispace d), (forall idx pf, bound_idx d idx is pf -> nat) -> Type := RectArray: forall (d:nat) sh_f val_f, array d (Rect d sh_f) val_f.
I define type families for rectangular index-spaces, for indices and for an index that is bounded by a rectangular index-space. The array type is a function from a restricted index-space to nat.
Now, I am trying to construct an array from such a function:
Definition func_to_arr d is (af:forall idx pf, bound_idx d idx is pf -> nat) := match is with | Rect d f => RectArray d f af end.
And Coq tells me:
Error: In environment d : nat is : ispace d af : forall (idx : index d) (pf : Prop), bound_idx d idx is pf -> nat d0 : nat f : t d0 -> nat The term "af" has type "forall (idx : index d) (pf : Prop), bound_idx d idx is pf -> nat" while it is expected to have type "forall (idx : index d0) (pf : Prop), bound_idx d0 idx (Rect d0 f) pf -> nat" (cannot unify "index d0" and "index d").
So I am wondering, how can I pass this information to the above definition, so that it becomes valid. Unless I misunderstand something, the type of af contains all the necessary information to reconstruct an array.