Debian Codegraph @

test-suite/success/AdvancedTypeClasses.v

raw
1 Generalizable All Variables.
2
3 Open Scope type_scope.
4
5 Section type_reification.
6
7 Inductive term :Type :=
8 Fun : term -> term -> term
9 | Prod : term -> term -> term
10 | Bool : term
11 | SET :term
12 | PROP :term
13 | TYPE :term
14 | Var : Type -> term.
15
16 Fixpoint interp (t:term) :=
17 match t with
18 Bool => bool
19 | SET => Set
20 | PROP => Prop
21 | TYPE => Type
22 | Fun a b => interp a -> interp b
23 | Prod a b => interp a * interp b
24 | Var x => x
25 end.
26
27 Class interp_pair (abs : Type) :=
28 { repr : term;
29 link: abs = interp repr }.
30
31 Arguments repr _ {interp_pair}.
32 Arguments link _ {interp_pair}.
33
34 Lemma prod_interp `{interp_pair a, interp_pair b} : a * b = interp (Prod (repr a) (repr b)).
35 simpl. intros. rewrite <- link. rewrite <- (link b). reflexivity.
36 Qed.
37
38 Lemma fun_interp :forall `{interp_pair a, interp_pair b}, (a -> b) = interp (Fun (repr a) (repr b)).
39 simpl. intros. rewrite <- link. rewrite <- (link b). reflexivity.
40 Qed.
41
42 Coercion repr : interp_pair >-> term.
43
44 Definition abs `{interp_pair a} : Type := a.
45 Coercion abs : interp_pair >-> Sortclass.
46
47 Lemma fun_interp' :forall `{ia : interp_pair, ib : interp_pair}, (ia -> ib) = interp (Fun ia ib).
48 simpl. intros a ia b ib. rewrite <- link. rewrite <- (link b). reflexivity.
49 Qed.
50
51 Instance ProdCan `(interp_pair a, interp_pair b) : interp_pair (a * b) :=
52 { repr := Prod (repr a) (repr b) ; link := prod_interp }.
53
54 Instance FunCan `(interp_pair a, interp_pair b) : interp_pair (a -> b) :=
55 { link := fun_interp }.
56
57 Instance BoolCan : interp_pair bool :=
58 { repr := Bool ; link := refl_equal _ }.
59
60 Instance VarCan x : interp_pair x | 10 := { repr := Var x ; link := refl_equal _ }.
61 Instance SetCan : interp_pair Set := { repr := SET ; link := refl_equal _ }.
62 Instance PropCan : interp_pair Prop := { repr := PROP ; link := refl_equal _ }.
63 Instance TypeCan : interp_pair Type := { repr := TYPE ; link := refl_equal _ }.
64
65 (* Print Canonical Projections. *)
66
67 Variable A:Type.
68
69 Variable Inhabited: term -> Prop.
70
71 Variable Inhabited_correct: forall `{interp_pair p}, Inhabited (repr p) -> p.
72
73 Lemma L : Prop * A -> bool * (Type -> Set) .
74 apply Inhabited_correct.
75 change (Inhabited (Fun (Prod PROP (Var A)) (Prod Bool (Fun TYPE SET)))).
76 Admitted.
77
78 End type_reification.