Debian Codegraph @

test-suite/bugs/bug_5683.v

raw
1 Require Import Program.Tactics.
2 Require Import TestSuite.funext.
3
4 Inductive Succ A :=
5 | Succ_O : Succ A
6 | Succ_S : A -> Succ A.
7 Arguments Succ_O {A}.
8 Arguments Succ_S {A} _.
9
10 Inductive Zero : Type :=.
11
12 Inductive ty :=
13 | ty_nat : ty
14 | ty_arr : ty -> ty -> ty.
15
16 Inductive term A :=
17 | term_abs : ty -> term (Succ A) -> term A
18 | term_app : term A -> term A -> term A
19 | term_var : A -> term A
20 | term_nat : nat -> term A.
21 Arguments term_abs {A} _ _.
22 Arguments term_app {A} _ _.
23 Arguments term_var {A} _.
24 Arguments term_nat {A} _.
25
26 Class Functor F :=
27 {
28 ret : forall {A}, A -> F A;
29 fmap : forall {A B}, (A -> B) -> F A -> F B;
30 fmap_id : forall {A} (fa : F A), fmap (@id A) fa = fa;
31 fmap_compose : forall {A B C} (fa : F A) (g : B -> C) (h : A -> B), fmap (fun
32 a => g (h a)) fa = fmap g (fmap h fa)
33 }.
34
35 Class Monad M `{Functor M} :=
36 {
37 bind : forall {A B}, M A -> (A -> M B) -> M B;
38 ret_left_id : forall {A B} (a : A) (f : A -> M B), bind (ret a) f = f a;
39 ret_right_id : forall {A} (m : M A), bind m ret = m;
40 bind_assoc : forall {A B C} (m : M A) (f : A -> M B) (g : B -> M C), bind
41 (bind m f) g = bind m (fun x => bind (f x) g)
42 }.
43
44 #[export] Instance Succ_Functor : Functor Succ.
45 Proof.
46 unshelve econstructor.
47 - intros A B f fa.
48 destruct fa.
49 + apply Succ_O.
50 + apply Succ_S. tauto.
51 - intros. apply Succ_S. assumption.
52 - intros A [|a]; reflexivity.
53 - intros A B C [|a] g h; reflexivity.
54 Defined.
55
56 (* Anomaly: Not an arity *)
57 Program Fixpoint term_bind {A B} (tm : term A) (f : A -> term B) : term B :=
58 let Succ_f (var : Succ A) :=
59 match var with
60 | Succ_O => term_var Succ_O
61 | Succ_S var' => _
62 end in
63 match tm with
64 | term_app tm1 tm2 => term_app (term_bind tm1 f) (term_bind tm2 f)
65 | term_abs ty body => term_abs ty (term_bind body Succ_f)
66 | term_var a => f a
67 | term_nat n => term_nat n
68 end.
69 Next Obligation.
70 intros.
71 Admitted.