Skip to content

Commit 4594829

Browse files
committed
style: prefer some/none over .some/.none (leanprover-community#27896)
The notation `.some` and `.none` are very useful when working with other inductive types such as `LOption` which have fields names `some` and/or `none`. But for `Option`, we prefer to simply write `some`/`none`. [#mathlib4 > style: &#96;.some&#96;/&#96;.none&#96; vs &#96;some&#96;/&#96;none&#96;](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/style.3A.20.60.2Esome.60.2F.60.2Enone.60.20vs.20.60some.60.2F.60none.60) Co-authored-by: Jovan Gerbscheid <jovan.gerbscheid@gmail.com>
1 parent c5bf9c5 commit 4594829

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+234
-235
lines changed

Cache/IO.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Usually it is either `.` or something like `./.lake/packages/mathlib/`
157157
-/
158158
def getSrcDir (sp : SearchPath) (mod : Name) : IO FilePath := do
159159

160-
let .some srcDir ← sp.findWithExtBase "lean" mod |
160+
let some srcDir ← sp.findWithExtBase "lean" mod |
161161
throw <| IO.userError s!"Unknown package directory for {mod}\nsearch paths: {sp}"
162162

163163
return srcDir

Counterexamples/ZeroDivisorsInAddMonoidAlgebras.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ elab "guard_decl" na:ident mod:ident : command => do
137137
let dcl ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo na
138138
let mdn := mod.getId
139139
let env ← getEnv
140-
let .some dcli := env.getModuleIdxFor? dcl | unreachable!
141-
let .some mdni := env.getModuleIdx? mdn | throwError "the module {mod} is not imported!"
140+
let some dcli := env.getModuleIdxFor? dcl | unreachable!
141+
let some mdni := env.getModuleIdx? mdn | throwError "the module {mod} is not imported!"
142142
unless dcli = mdni do throwError "instance {na} is no longer in {mod}."
143143

144144
guard_decl Finsupp.Lex.addLeftMono Mathlib.Data.Finsupp.Lex

LongestPole/Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ open System in
124124
def countLOC (modules : List Name) : IO (NameMap Float) := do
125125
let mut r := {}
126126
for m in modules do
127-
if let .some fp ← Lean.SearchPath.findModuleWithExt [s!".{FilePath.pathSeparator}"] "lean" m
127+
if let some fp ← Lean.SearchPath.findModuleWithExt [s!".{FilePath.pathSeparator}"] "lean" m
128128
then
129129
let src ← IO.FS.readFile fp
130130
r := r.insert m (src.toList.count '\n').toFloat

Mathlib/Algebra/Order/BigOperators/Expect.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def evalFinsetExpect : PositivityExt where eval {u α} zα pα e := do
188188
let rbody ← core zα pα body
189189
let p_pos : Option Q(0 < $e) := ← (do
190190
let .positive pbody := rbody | pure none -- Fail if the body is not provably positive
191-
let .some ps ← proveFinsetNonempty s | pure none
191+
let some ps ← proveFinsetNonempty s | pure none
192192
let .some pα' ← trySynthInstanceQ q(IsOrderedCancelAddMonoid $α) | pure none
193193
let .some instαordsmul ← trySynthInstanceQ q(PosSMulStrictMono ℚ≥0 $α) | pure none
194194
assumeInstancesCommute

Mathlib/Algebra/Order/BigOperators/Ring/Finset.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def evalFinsetProd : PositivityExt where eval {u α} zα pα e := do
292292
if let some p_pos := p_pos then return .positive p_pos
293293
-- Try to show that the product is nonnegative
294294
let p_nonneg : Option Q(0 ≤ $e) := ← do
295-
let .some pbody := rbody.toNonneg
295+
let some pbody := rbody.toNonneg
296296
| return none -- Fail if the body is not provably nonnegative
297297
let pr : Q(∀ i, 0 ≤ $f i) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
298298
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.

Mathlib/Data/DFinsupp/Notation.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ attribute [term_parser] Finsupp.stxSingle₀ Finsupp.stxUpdate₀
2828
def elabSingle₀ : Elab.Term.TermElab
2929
| `(term| single₀ $i $x) => fun ty? => do
3030
Elab.Term.tryPostponeIfNoneOrMVar ty?
31-
let .some ty := ty? | Elab.throwUnsupportedSyntax
31+
let some ty := ty? | Elab.throwUnsupportedSyntax
3232
let_expr DFinsupp _ _ _ := ← Meta.withReducible (Meta.whnf ty) | Elab.throwUnsupportedSyntax
3333
Elab.Term.elabTerm (← `(DFinsupp.single $i $x)) ty?
3434
| _ => fun _ => Elab.throwUnsupportedSyntax
@@ -38,7 +38,7 @@ def elabSingle₀ : Elab.Term.TermElab
3838
def elabUpdate₀ : Elab.Term.TermElab
3939
| `(term| update₀ $f $i $x) => fun ty? => do
4040
Elab.Term.tryPostponeIfNoneOrMVar ty?
41-
let .some ty := ty? | Elab.throwUnsupportedSyntax
41+
let some ty := ty? | Elab.throwUnsupportedSyntax
4242
let_expr DFinsupp _ _ _ := ← Meta.withReducible (Meta.whnf ty) | Elab.throwUnsupportedSyntax
4343
Elab.Term.elabTerm (← `(DFinsupp.update $f $i $x)) ty?
4444
| _ => fun _ => Elab.throwUnsupportedSyntax

Mathlib/Data/EReal/Operations.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,11 +872,11 @@ def evalERealMul : PositivityExt where eval {u α} zα pα e := do
872872
| _ => pure .none
873873
| .nonnegative pa =>
874874
match (← core zα pα b).toNonneg with
875-
| .some pb => pure (.nonnegative q(EReal.mul_nonneg $pa $pb))
876-
| .none => pure .none
875+
| some pb => pure (.nonnegative q(EReal.mul_nonneg $pa $pb))
876+
| none => pure .none
877877
| .nonzero pa =>
878878
match (← core zα pα b).toNonzero with
879-
| .some pb => pure (.nonzero q(mul_ne_zero $pa $pb))
879+
| some pb => pure (.nonzero q(mul_ne_zero $pa $pb))
880880
| none => pure .none
881881
| _ => pure .none
882882
| _, _, _ => throwError "not a product of 2 `EReal`s"

Mathlib/Data/Fin/Tuple/Reflection.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ simproc_decl prod_univ_ofNat (∏ _ : Fin _, _) := .ofQ fun u _ e => do
223223
match u, e with
224224
| .succ _, ~q(@Finset.prod (Fin $n) _ $inst (@Finset.univ _ $instF) $f) => do
225225
match (generalizing := false) n.nat? with
226-
| .none =>
226+
| none =>
227227
return .continue
228-
| .some nVal =>
228+
| some nVal =>
229229
let ⟨res, pf⟩ ← mkProdEqQ inst nVal f
230230
let ⟨_⟩ ← assertDefEqQ q($instF) q(Fin.fintype _)
231231
have _ : $n =Q $nVal := ⟨⟩
@@ -237,9 +237,9 @@ simproc_decl sum_univ_ofNat (∑ _ : Fin _, _) := .ofQ fun u _ e => do
237237
match u, e with
238238
| .succ _, ~q(@Finset.sum (Fin $n) _ $inst (@Finset.univ _ $instF) $f) => do
239239
match n.nat? with
240-
| .none =>
240+
| none =>
241241
return .continue
242-
| .some nVal =>
242+
| some nVal =>
243243
let ⟨res, pf⟩ ← mkSumEqQ inst nVal f
244244
let ⟨_⟩ ← assertDefEqQ q($instF) q(Fin.fintype _)
245245
have _ : $n =Q $nVal := ⟨⟩

Mathlib/Data/Fin/VecNotation.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ dsimproc cons_val (Matrix.vecCons _ _ _) := fun e => do
163163
let etailn_whnf : Q(ℕ) ← Meta.whnfD etailn
164164
if let Expr.lit (.natVal length) := etailn_whnf then
165165
pure (length, false, q(OfNat.ofNat $etailn_whnf))
166-
else if let .some ((base : Q(ℕ)), offset) ← (Meta.isOffset? etailn_whnf).run then
166+
else if let some ((base : Q(ℕ)), offset) ← (Meta.isOffset? etailn_whnf).run then
167167
let offset_e : Q(ℕ) := mkNatLit offset
168168
pure (offset, true, q($base + $offset))
169169
else

Mathlib/Data/Finsupp/Option.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ theorem embDomain_some_some [Zero M] (f : α →₀ M) (x) : f.embDomain .some (
6767

6868
@[simp]
6969
theorem some_update_none [Zero M] (f : Option α →₀ M) (a : M) :
70-
(f.update .none a).some = f.some := by
70+
(f.update none a).some = f.some := by
7171
ext
7272
simp [Finsupp.update]
7373

@@ -76,8 +76,8 @@ pairs of an element and a `Finsupp` on the original type. -/
7676
@[simps]
7777
noncomputable
7878
def optionEquiv [Zero M] : (Option α →₀ M) ≃ M × (α →₀ M) where
79-
toFun P := (P .none, P.some)
80-
invFun P := (P.2.embDomain .some).update .none P.1
79+
toFun P := (P none, P.some)
80+
invFun P := (P.2.embDomain .some).update none P.1
8181
left_inv P := by ext (_ | a) <;> simp [Finsupp.update]
8282
right_inv P := by ext <;> simp [Finsupp.update]
8383

@@ -108,7 +108,7 @@ theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : O
108108
@[simp] lemma some_embDomain_some [Zero M] (f : α →₀ M) : (f.embDomain .some).some = f := by
109109
ext; rw [some_apply]; exact embDomain_apply _ _ _
110110

111-
@[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some .none = 0 :=
111+
@[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some none = 0 :=
112112
embDomain_notin_range _ _ _ (by simp)
113113

114114
end Option

0 commit comments

Comments
 (0)