| 1 |
(* Specific tests about guard condition *) |
| 2 |
|
| 3 |
(* f must unfold to x, not F (de Bruijn mix-up!) *) |
| 4 |
Check let x (f:nat->nat) k := f k in |
| 5 |
fun (y z:nat->nat) => |
| 6 |
let f:=x in (* f := Rel 3 *) |
| 7 |
fix F (n:nat) : nat := |
| 8 |
match n with |
| 9 |
| 0 => 0 |
| 10 |
| S k => f F k (* here Rel 3 = F ! *) |
| 11 |
end. |
| 12 |
|
| 13 |
(** Commutation of guard condition allows recursive calls on functional arguments, |
| 14 |
despite rewriting in their domain types. *) |
| 15 |
Inductive foo : Type -> Type := |
| 16 |
| End A : foo A |
| 17 |
| Next A : (A -> foo A) -> foo A. |
| 18 |
|
| 19 |
Definition nat : Type := nat. |
| 20 |
|
| 21 |
Fixpoint bar (A : Type) (e : nat = A) (f : foo A) {struct f} : nat := |
| 22 |
match f with |
| 23 |
| End _ => fun _ => O |
| 24 |
| Next A g => fun e => |
| 25 |
match e in (_ = B) return (B -> foo A) -> nat with |
| 26 |
| eq_refl => fun (g' : nat -> foo A) => bar A e (g' O) |
| 27 |
end g |
| 28 |
end e. |