Skip to content

Commit

Permalink
Add Util.Option.bind2
Browse files Browse the repository at this point in the history
To replace `RingMicromega.map_option2` in
#1609
  • Loading branch information
JasonGross committed Dec 4, 2023
1 parent 2cd94bb commit 7fa59dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Util/Notations.v
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ Reserved Notation "A <-- X ; B" (at level 70, X at next level, right associativi
Reserved Notation "A <--- X ; B" (at level 70, X at next level, right associativity, format "'[v' A <--- X ; '/' B ']'").
Reserved Notation "A <---- X ; B" (at level 70, X at next level, right associativity, format "'[v' A <---- X ; '/' B ']'").
Reserved Notation "A <----- X ; B" (at level 70, X at next level, right associativity, format "'[v' A <----- X ; '/' B ']'").
Reserved Notation "A , A' <- X , X' ; B" (at level 70, A' at next level, X at next level, X' at next level, right associativity, format "'[v' A , A' <- X , X' ; '/' B ']'").
Reserved Notation "A , A' <-- X , X' ; B" (at level 70, A' at next level, X at next level, X' at next level, right associativity, format "'[v' A , A' <-- X , X' ; '/' B ']'").
Reserved Notation "A , A' <--- X , X' ; B" (at level 70, A' at next level, X at next level, X' at next level, right associativity, format "'[v' A , A' <--- X , X' ; '/' B ']'").
Reserved Notation "A , A' <---- X , X' ; B" (at level 70, A' at next level, X at next level, X' at next level, right associativity, format "'[v' A , A' <---- X , X' ; '/' B ']'").
Reserved Notation "A , A' <----- X , X' ; B" (at level 70, A' at next level, X at next level, X' at next level, right associativity, format "'[v' A , A' <----- X , X' ; '/' B ']'").
Reserved Notation "A ;; B" (at level 70, right associativity, format "'[v' A ;; '/' B ']'").
Reserved Notation "A ';;L' B" (at level 70, right associativity, format "'[v' A ';;L' '/' B ']'").
Reserved Notation "A ';;R' B" (at level 70, right associativity, format "'[v' A ';;R' '/' B ']'").
Expand Down
10 changes: 10 additions & 0 deletions src/Util/Option.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ Definition bind {A B} (v : option A) (f : A -> option B) : option B
| None => None
end.

Definition bind2 {A B C} (v1 : option A) (v2 : option B) (f : A -> B -> option C) : option C
:= match v1, v2 with
| None, _
| _, None
=> None
| Some x1, Some x2 => f x1 x2
end.
Global Arguments bind2 {A B C} !v1 !v2 / f.

Definition sequence {A} (v1 v2 : option A) : option A
:= match v1 with
| Some v => Some v
Expand All @@ -59,6 +68,7 @@ Module Export Notations.

Notation "'olet' x .. y <- X ; B" := (bind X (fun x => .. (fun y => B%option) .. )) : option_scope.
Notation "A <- X ; B" := (bind X (fun A => B%option)) : option_scope.
Notation "A , A' <- X , X' ; B" := (bind2 X X' (fun A A' => B%option)) : option_scope.
Infix ";;" := sequence : option_scope.
Infix ";;;" := sequence_return : option_scope.
End Notations.
Expand Down

0 comments on commit 7fa59dc

Please sign in to comment.