| 1 |
(* Treat "match" on a "cofix" like "match" on a constructor in guard condition *) |
| 2 |
|
| 3 |
Module CofixRedex. |
| 4 |
|
| 5 |
CoInductive Stream := {hd : nat; tl : Stream}. |
| 6 |
Definition zeros := cofix zeros := {|hd := 0; tl := zeros|}. |
| 7 |
|
| 8 |
Fixpoint f n := |
| 9 |
match n with |
| 10 |
| 0 => 0 |
| 11 |
| S n => |
| 12 |
match zeros with |
| 13 |
| {|hd:=_|} => fun f => f n |
| 14 |
end f |
| 15 |
end. |
| 16 |
|
| 17 |
End CofixRedex. |
| 18 |
|
| 19 |
Module CofixRedexPrimProj. |
| 20 |
|
| 21 |
Set Primitive Projections. |
| 22 |
CoInductive Stream A := {hd : A; tl : Stream A}. |
| 23 |
Arguments hd {A} s. |
| 24 |
|
| 25 |
Fixpoint f n := |
| 26 |
match n with |
| 27 |
| 0 => 0 |
| 28 |
| S n => (cofix cst := {|hd := (fun f => f n); tl := cst|}).(hd) f |
| 29 |
end. |
| 30 |
|
| 31 |
End CofixRedexPrimProj. |
| 32 |
|
| 33 |
(* Stack was missing when unfolding primitive projection in guard condition *) |
| 34 |
|
| 35 |
Module ProjectionStack. |
| 36 |
|
| 37 |
Set Primitive Projections. |
| 38 |
|
| 39 |
Record T := { a : nat -> nat }. |
| 40 |
|
| 41 |
Check fix f (b:bool) n : nat := |
| 42 |
match n with |
| 43 |
| 0 => 0 |
| 44 |
| S n => (if b then {| a := f b |}.(a) else f b) n |
| 45 |
end. |
| 46 |
|
| 47 |
End ProjectionStack. |