Skip to content

Commit

Permalink
coq-8.13 port
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaliva committed Jan 29, 2021
1 parent 91b6559 commit 9cf3541
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ nra.cache
/Makefile.coq.conf
/theories/*.vos
/.Makefile.coq.d
*.vok
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ Definition Ex1 (n:nat) : T :=
# Contact #

* Repository: https://github.com/vzaliva/coq-switch
* Questions: [Vadim Zaliva](mailto:vzaliva@cmu.edu)
* Questions: [Vadim Zaliva](mailto:lord@crocodile.org)
12 changes: 6 additions & 6 deletions coq-switch.opam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ maintainer: "vzaliva@cmu.edu"
homepage: "https://github.com/vzaliva/coq-switch"
dev-repo: "git://git@github.com:vzaliva/coq-switch.git"
bug-reports: "https://github.com/vzaliva/coq-switch/issues"
authors: ["Vadim Zaliva <vzaliva@cmu.edu>"]
authors: ["Vadim Zaliva <lord@crocodile.org>"]
license: "MIT"
build: [
[make "-j%{jobs}%"]
Expand All @@ -12,15 +12,15 @@ install: [
[make "install"]
]
depends: [
"coq" {>= "8.12.0"}
"coq-metacoq-template" {>= "1.0~beta1+8.12"}
"coq" {>= "8.13.0"}
"coq-metacoq-template" {>= "1.0~beta2+8.13"}
]
tags: [
"category:Miscellaneous/Coq Extensions"
"date:2020-09-24"
"date:2021-01-28"
"logpath:Switch"
]
synopsis: "A plugin to implement functionality similar to `switch` statement in C language."
synopsis: "A plugin to implement functionality similar to `switch` statement in C language"

description: """It allows easier dispatch on several constant values
of a type with decidable equality. Given a type, boolean equality
Expand All @@ -29,7 +29,7 @@ an inductive type with constructors, one for each of the choices, and
a function mapping values to this type."""

url {
src: "https://github.com/vzaliva/coq-switch/archive/v1.0.4.tar.gz"
src: "https://github.com/vzaliva/coq-switch/archive/v1.0.5.tar.gz"
checksum: ""
}

5 changes: 5 additions & 0 deletions demo.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ MetaCoq Run
| None => 0
end.

Compute Ex1 10.

End NatExample.

Definition string_beq a b :=
Expand Down Expand Up @@ -60,4 +62,7 @@ Section StringExample.
| None => 0
end.

Compute Ex2 "ten".
Compute Ex2 "xxx".

End StringExample.
10 changes: 6 additions & 4 deletions theories/Switch.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Import ListNotations.

Open Scope string_scope.

Definition rname (s:string) := {| binder_name := nNamed s; binder_relevance := Relevant |}.

Fixpoint mkSwitchCases
(type_name: kername)
(A_t: term)
Expand All @@ -22,10 +24,10 @@ Fixpoint mkSwitchCases
| [] => tApp (tConstruct opt_i 1 []) [tInd T_i []]
| (x::xs) => tCase
(* # of parameters *)
(bool_i, 0)
((bool_i, 0), Relevant)

(* type info *)
(tLambda (nNamed "b") (tInd bool_i []) (tApp (tInd opt_i []) [tInd T_i []]))
(tLambda (rname "b") (tInd bool_i []) (tApp (tInd opt_i []) [tInd T_i []]))

(* discriminee *)
(tApp P_t [tRel 0; x])
Expand Down Expand Up @@ -59,7 +61,7 @@ Definition mkSwitch
mind_entry_inds := [one_i] ;
mind_entry_universes := Monomorphic_entry (LevelSet.empty, ConstraintSet.empty);
mind_entry_template := false ;
mind_entry_cumulative := false ;
mind_entry_variance := None ;
mind_entry_private := None (* or (Some false)? *)
|} in
mp <- tmCurrentModPath tt ;;
Expand All @@ -68,7 +70,7 @@ Definition mkSwitch
A_t <- tmQuote A ;;
P_t <- tmQuote P ;;
choices_t <- monad_map (fun x => tmQuote (fst x)) choices ;;
let body_t := tLambda (nNamed "x") A_t (mkSwitchCases (mp, type_name) A_t P_t choices_t 0) in
let body_t := tLambda (rname "x") A_t (mkSwitchCases (mp, type_name) A_t P_t choices_t 0) in
body <- tmUnquoteTyped (A -> option T) body_t ;;
def_t <- tmDefinition def_name body ;;
tmReturn tt.

0 comments on commit 9cf3541

Please sign in to comment.