-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.v
69 lines (50 loc) · 1.35 KB
/
demo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Require Import Switch.Switch.
Require Import Coq.Arith.EqNat.
Require Import Coq.Strings.String.
Require Import Coq.Lists.List.
Require Import MetaCoq.Template.All.
Import ListNotations.
Open Scope string_scope.
Section NatExample.
(* This example uses standard list notation for choices *)
MetaCoq Run
(mkSwitch nat
Nat.eqb
[(0,"Love") ; (10,"Ten") ; (20, "twenty")]
"Ex1_Choices" "ex1_select"
).
Print Ex1_Choices.
Print ex1_select.
Definition Ex1 (n:nat): nat :=
match ex1_select n with
| Some Love => 100
| Some Ten => 110
| Some Twenty => 120
| None => 0
end.
Compute Ex1 10.
End NatExample.
Definition string_beq a b :=
if string_dec a b then true else false.
Section StringExample.
(* This example custom -> notation for choices *)
Infix "->" := pair.
MetaCoq Run
(mkSwitch String.string string_beq [
"love" -> "SLove" ;
"ten" -> "STen" ;
"twenty" -> "STwenty"
] "Ex2_Choices" "ex2_select"
).
Print Ex2_Choices.
Print ex2_select.
Definition Ex2 (s:String.string) : nat :=
match ex2_select s with
| Some SLove => 100
| Some STen => 110
| Some STwenty => 120
| None => 0
end.
Compute Ex2 "ten".
Compute Ex2 "xxx".
End StringExample.