Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stdpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Iris
stdpp
Commits
d8445c86
Commit
d8445c86
authored
12 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Add a type class to collect types that are inhabited.
parent
507a150a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
theories/base.v
+22
-0
22 additions, 0 deletions
theories/base.v
theories/numbers.v
+5
-0
5 additions, 0 deletions
theories/numbers.v
with
27 additions
and
0 deletions
theories/base.v
+
22
−
0
View file @
d8445c86
...
...
@@ -86,6 +86,28 @@ on a type [A] we write [`{∀ x y : A, Decision (x = y)}] and use it by writing
Class
Decision
(
P
:
Prop
)
:=
decide
:
{
P
}
+
{
¬
P
}
.
Arguments
decide
_
{_}
.
(** ** Inhabited types *)
(** This type class collects types that are inhabited. *)
Class
Inhabited
(
A
:
Type
)
:
Prop
:=
populate
{
_
:
A
}
.
Arguments
populate
{_}
_
.
Instance
unit_inhabited
:
Inhabited
unit
:=
populate
()
.
Instance
list_inhabited
{
A
}
:
Inhabited
(
list
A
)
:=
populate
[]
.
Instance
prod_inhabited
{
A
B
}
(
iA
:
Inhabited
A
)
(
iB
:
Inhabited
B
)
:
Inhabited
(
A
*
B
)
:=
match
iA
,
iB
with
|
populate
x
,
populate
y
=>
populate
(
x
,
y
)
end
.
Instance
sum_inhabited_l
{
A
B
}
(
iA
:
Inhabited
A
)
:
Inhabited
(
A
+
B
)
:=
match
iA
with
|
populate
x
=>
populate
(
inl
x
)
end
.
Instance
sum_inhabited_r
{
A
B
}
(
iB
:
Inhabited
A
)
:
Inhabited
(
A
+
B
)
:=
match
iB
with
|
populate
y
=>
populate
(
inl
y
)
end
.
Instance
option_inhabited
{
A
}
:
Inhabited
(
option
A
)
:=
populate
None
.
(** ** Setoid equality *)
(** We define an operational type class for setoid equality. This is based on
(Spitters/van der Weegen, 2011). *)
...
...
This diff is collapsed.
Click to expand it.
theories/numbers.v
+
5
−
0
View file @
d8445c86
...
...
@@ -25,6 +25,7 @@ Infix "`mod`" := NPeano.modulo (at level 35) : nat_scope.
Instance
nat_eq_dec
:
∀
x
y
:
nat
,
Decision
(
x
=
y
)
:=
eq_nat_dec
.
Instance
nat_le_dec
:
∀
x
y
:
nat
,
Decision
(
x
≤
y
)
:=
le_dec
.
Instance
nat_lt_dec
:
∀
x
y
:
nat
,
Decision
(
x
<
y
)
:=
lt_dec
.
Instance
nat_inhabited
:
Inhabited
nat
:=
populate
0
%
nat
.
Lemma
lt_n_SS
n
:
n
<
S
(
S
n
)
.
Proof
.
auto
with
arith
.
Qed
.
...
...
@@ -40,6 +41,8 @@ Definition sum_list_with {A} (f : A → nat) : list A → nat :=
Notation
sum_list
:=
(
sum_list_with
id
)
.
Instance
positive_eq_dec
:
∀
x
y
:
positive
,
Decision
(
x
=
y
)
:=
Pos
.
eq_dec
.
Instance
positive_inhabited
:
Inhabited
positive
:=
populate
1
%
positive
.
Notation
"(~0)"
:=
xO
(
only
parsing
)
:
positive_scope
.
Notation
"(~1)"
:=
xI
(
only
parsing
)
:
positive_scope
.
...
...
@@ -75,6 +78,7 @@ Program Instance N_lt_dec (x y : N) : Decision (x < y)%N :=
|
_
=>
right
_
end
.
Next
Obligation
.
congruence
.
Qed
.
Instance
N_inhabited
:
Inhabited
N
:=
populate
1
%
N
.
Infix
"≤"
:=
Z
.
le
:
Z_scope
.
Notation
"x ≤ y ≤ z"
:=
(
x
≤
y
∧
y
≤
z
)
%
Z
:
Z_scope
.
...
...
@@ -87,6 +91,7 @@ Notation "(<)" := Z.lt (only parsing) : Z_scope.
Instance
Z_eq_dec
:
∀
x
y
:
Z
,
Decision
(
x
=
y
)
:=
Z
.
eq_dec
.
Instance
Z_le_dec
:
∀
x
y
:
Z
,
Decision
(
x
≤
y
)
%
Z
:=
Z_le_dec
.
Instance
Z_lt_dec
:
∀
x
y
:
Z
,
Decision
(
x
<
y
)
%
Z
:=
Z_lt_dec
.
Instance
Z_inhabited
:
Inhabited
Z
:=
populate
1
%
Z
.
(** * Conversions *)
(** The function [Z_to_option_N] converts an integer [x] into a natural number
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment