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
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Glen Mével
stdpp
Commits
b9117014
Commit
b9117014
authored
10 years ago
by
Robbert Krebbers
Browse files
Options
Downloads
Patches
Plain Diff
Add monoid operation on option.
parent
71214d32
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theories/option.v
+41
-35
41 additions, 35 deletions
theories/option.v
with
41 additions
and
35 deletions
theories/option.v
+
41
−
35
View file @
b9117014
...
...
@@ -138,6 +138,46 @@ Qed.
Lemma
bind_with_Some
{
A
}
(
x
:
option
A
)
:
x
≫=
Some
=
x
.
Proof
.
by
destruct
x
.
Qed
.
(** * Union, intersection and difference *)
Instance
option_union_with
{
A
}
:
UnionWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
|
Some
a
,
Some
b
=>
f
a
b
|
Some
a
,
None
=>
Some
a
|
None
,
Some
b
=>
Some
b
|
None
,
None
=>
None
end
.
Instance
option_intersection_with
{
A
}
:
IntersectionWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
Some
a
,
Some
b
=>
f
a
b
|
_,
_
=>
None
end
.
Instance
option_difference_with
{
A
}
:
DifferenceWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
|
Some
a
,
Some
b
=>
f
a
b
|
Some
a
,
None
=>
Some
a
|
None
,
_
=>
None
end
.
Instance
option_union
{
A
}
:
Union
(
option
A
)
:=
union_with
(
λ
x
_,
Some
x
)
.
Lemma
option_union_Some
{
A
}
(
x
y
:
option
A
)
z
:
x
∪
y
=
Some
z
→
x
=
Some
z
∨
y
=
Some
z
.
Proof
.
destruct
x
,
y
;
intros
;
simplify_equality
;
auto
.
Qed
.
Section
option_union_intersection_difference
.
Context
{
A
}
(
f
:
A
→
A
→
option
A
)
.
Global
Instance
:
LeftId
(
=
)
None
(
union_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
RightId
(
=
)
None
(
union_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
Commutative
(
=
)
f
→
Commutative
(
=
)
(
union_with
f
)
.
Proof
.
by
intros
?
[?|]
[?|];
compute
;
rewrite
1
?(
commutative
f
)
.
Qed
.
Global
Instance
:
LeftAbsorb
(
=
)
None
(
intersection_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
RightAbsorb
(
=
)
None
(
intersection_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
Commutative
(
=
)
f
→
Commutative
(
=
)
(
intersection_with
f
)
.
Proof
.
by
intros
?
[?|]
[?|];
compute
;
rewrite
1
?(
commutative
f
)
.
Qed
.
Global
Instance
:
RightId
(
=
)
None
(
difference_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
End
option_union_intersection_difference
.
(** * Tactics *)
Tactic
Notation
"case_option_guard"
"as"
ident
(
Hx
)
:=
match
goal
with
|
H
:
context
C
[
@
mguard
option
_
?P
?dec
_
?x
]
|
-
_
=>
...
...
@@ -199,6 +239,7 @@ Tactic Notation "simplify_option_equality" "by" tactic3(tac) :=
repeat
match
goal
with
|
_
=>
progress
simplify_equality'
|
_
=>
progress
simpl_option_monad
by
tac
|
H
:
_
∪
_
=
Some
_
|
-
_
=>
apply
option_union_Some
in
H
;
destruct
H
|
H
:
mbind
(
M
:=
option
)
?f
?o
=
?x
|
-
_
=>
match
o
with
Some
_
=>
fail
1
|
None
=>
fail
1
|
_
=>
idtac
end
;
match
x
with
Some
_
=>
idtac
|
None
=>
idtac
|
_
=>
fail
1
end
;
...
...
@@ -223,38 +264,3 @@ Tactic Notation "simplify_option_equality" "by" tactic3(tac) :=
|
_
=>
progress
case_option_guard
end
.
Tactic
Notation
"simplify_option_equality"
:=
simplify_option_equality
by
eauto
.
(** * Union, intersection and difference *)
Instance
option_union_with
{
A
}
:
UnionWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
|
Some
a
,
Some
b
=>
f
a
b
|
Some
a
,
None
=>
Some
a
|
None
,
Some
b
=>
Some
b
|
None
,
None
=>
None
end
.
Instance
option_intersection_with
{
A
}
:
IntersectionWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
Some
a
,
Some
b
=>
f
a
b
|
_,
_
=>
None
end
.
Instance
option_difference_with
{
A
}
:
DifferenceWith
A
(
option
A
)
:=
λ
f
x
y
,
match
x
,
y
with
|
Some
a
,
Some
b
=>
f
a
b
|
Some
a
,
None
=>
Some
a
|
None
,
_
=>
None
end
.
Section
option_union_intersection_difference
.
Context
{
A
}
(
f
:
A
→
A
→
option
A
)
.
Global
Instance
:
LeftId
(
=
)
None
(
union_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
RightId
(
=
)
None
(
union_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
Commutative
(
=
)
f
→
Commutative
(
=
)
(
union_with
f
)
.
Proof
.
by
intros
?
[?|]
[?|];
compute
;
rewrite
1
?(
commutative
f
)
.
Qed
.
Global
Instance
:
LeftAbsorb
(
=
)
None
(
intersection_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
RightAbsorb
(
=
)
None
(
intersection_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
Global
Instance
:
Commutative
(
=
)
f
→
Commutative
(
=
)
(
intersection_with
f
)
.
Proof
.
by
intros
?
[?|]
[?|];
compute
;
rewrite
1
?(
commutative
f
)
.
Qed
.
Global
Instance
:
RightId
(
=
)
None
(
difference_with
f
)
.
Proof
.
by
intros
[?|]
.
Qed
.
End
option_union_intersection_difference
.
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