LazyWeb to the rescue?
3 Apr 2010 07:10 amI've a question for any Coq users out there. How can you provide type equality constraints when doing case matching (ala GADT case matching in Haskell)? That is, assume we've defined something like:
And now we want to do something like:
Where the type of
( Edit: solution, for posterity )
Inductive Stack {A:Set} : nat -> nat -> Set :=
| stack : (m:nat) -> (n:nat) -> vector A m -> vector A n -> Stack m n.
And now we want to do something like:
Definition
foo {A:Set} {m n : nat} (s : stack (S m) n) (f : stack m (S n) -> (stack m (S n) *...)) ...
:= ...
match s with
| (stack (S m0) n0 (Vcons x0 _m0 xs0) ys0) =>
let s' := stack m0 (S n0) xs0 (Vcons _ x0 n0 ys0)
in match f s' with
| (stack m1 (S n1) xs1 (Vcons y1 _n1 ys1), ...
end
end.
Where the type of
f
is constrained to accept and return stacks with the "right" indices with respect to the parameter s
. I keep running into this problem where information about the length indices (i.e., what they're unified with) is getting lost by either one case match or the other. Hopefully I haven't simplified the example so much that you can't see why that would come up. I've tried playing around with different forms of match
and moving around the arguments to Stack/stack
to no avail. And my google-fu is failing me. Halp!( Edit: solution, for posterity )