Skip to content

Commit

Permalink
chore: fix codebase after removing auto pure
Browse files Browse the repository at this point in the history
  • Loading branch information
leodemoura committed Feb 4, 2022
1 parent 00f59a9 commit 12e2a79
Show file tree
Hide file tree
Showing 122 changed files with 674 additions and 677 deletions.
2 changes: 1 addition & 1 deletion src/Init/Data/Array/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def filter (p : α → Bool) (as : Array α) (start := 0) (stop := as.size) : Ar
@[inline]
def filterM [Monad m] (p : α → m Bool) (as : Array α) (start := 0) (stop := as.size) : m (Array α) :=
as.foldlM (init := #[]) (start := start) (stop := stop) fun r a => do
if (← p a) then r.push a else r
if (← p a) then return r.push a else return r

@[specialize]
def filterMapM [Monad m] (f : α → m (Option β)) (as : Array α) (start := 0) (stop := as.size) : m (Array β) :=
Expand Down
2 changes: 1 addition & 1 deletion src/Init/Meta.lean
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ instance : Quote Substring := ⟨fun s => Syntax.mkCApp `String.toSubstring #[qu

-- in contrast to `Name.toString`, we can, and want to be, precise here
private def getEscapedNameParts? (acc : List String) : Name → OptionM (List String)
| Name.anonymous => acc
| Name.anonymous => return acc
| Name.str n s _ => do
let s ← Name.escapePart s
getEscapedNameParts? (s::acc) n
Expand Down
6 changes: 3 additions & 3 deletions src/Init/Notation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end Lean.Parser.Syntax
macro "max" : prec => `(1024) -- maximum precedence used in term parsers, in particular for terms in function position (`ident`, `paren`, ...)
macro "arg" : prec => `(1023) -- precedence used for application arguments (`do`, `by`, ...)
macro "lead" : prec => `(1022) -- precedence used for terms not supposed to be used as arguments (`let`, `have`, ...)
macro "(" p:prec ")" : prec => p
macro "(" p:prec ")" : prec => return p
macro "min" : prec => `(10) -- minimum precedence used in term parsers
macro "min1" : prec => `(11) -- `(min+1) we can only `min+1` after `Meta.lean`
/-
Expand All @@ -35,7 +35,7 @@ macro "default" : prio => `(1000)
macro "low" : prio => `(100)
macro "mid" : prio => `(1000)
macro "high" : prio => `(10000)
macro "(" p:prio ")" : prio => p
macro "(" p:prio ")" : prio => return p

-- Basic notation for defining parsers
-- NOTE: precedence must be at least `arg` to be used in `macro` without parentheses
Expand Down Expand Up @@ -208,7 +208,7 @@ notation:50 e:51 " matches " p:51 => ((match e with | p => true | _ => false) :
-- Declare `this` as a keyword that unhygienically binds to a scope-less `this` assumption (or other binding).
-- The keyword prevents declaring a `this` binding except through metapgrogramming, as is done by `have`/`show`.
/-- Special identifier introduced by "anonymous" `have : ...`, `suffices p ...` etc. -/
macro tk:"this" : term => Syntax.ident tk.getHeadInfo "this".toSubstring `this []
macro tk:"this" : term => return Syntax.ident tk.getHeadInfo "this".toSubstring `this []

namespace Parser.Tactic
/--
Expand Down
6 changes: 3 additions & 3 deletions src/Init/Prelude.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ def Array.sequenceMap {α : Type u} {β : Type v} {m : Type v → Type w} [Monad
match i with
| 0 => pure bs
| Nat.succ i' => Bind.bind (f (as.get ⟨j, hlt⟩)) fun b => loop i' (hAdd j 1) (bs.push b))
(fun _ => bs)
(fun _ => pure bs)
loop as.size 0 Array.empty

/-- A Function for lifting a computation from an inner Monad to an outer Monad.
Expand Down Expand Up @@ -2032,8 +2032,8 @@ class MonadQuotation (m : Type → Type) extends MonadRef m where

export MonadQuotation (getCurrMacroScope getMainModule withFreshMacroScope)

def MonadRef.mkInfoFromRefPos [Monad m] [MonadRef m] : m SourceInfo := do
SourceInfo.fromRef (← getRef)
def MonadRef.mkInfoFromRefPos [Monad m] [MonadRef m] : m SourceInfo :=
return SourceInfo.fromRef (← getRef)

instance {m n : Type → Type} [MonadFunctor m n] [MonadLift m n] [MonadQuotation m] : MonadQuotation n where
getCurrMacroScope := liftM (m := m) getCurrMacroScope
Expand Down
16 changes: 8 additions & 8 deletions src/Init/System/IO.lean
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace EIO

/-- `EIO` specialization of `BaseIO.bindTask`. -/
@[inline] def bindTask (t : Task α) (f : α → EIO ε (Task (Except ε β))) (prio := Task.Priority.default) : BaseIO (Task (Except ε β)) :=
BaseIO.bindTask t (fun a => f a |>.catchExceptions fun e => Task.pure <| Except.error e) prio
BaseIO.bindTask t (fun a => f a |>.catchExceptions fun e => return Task.pure <| Except.error e) prio

/-- `EIO` specialization of `BaseIO.mapTasks`. -/
@[inline] def mapTasks (f : List α → EIO ε β) (tasks : List (Task α)) (prio := Task.Priority.default) : BaseIO (Task (Except ε β)) :=
Expand Down Expand Up @@ -200,7 +200,7 @@ def sleep (ms : UInt32) : IO Unit :=

/-- Wait for the task to finish, then return its result. -/
@[extern "lean_io_wait"] constant wait (t : Task α) : BaseIO α :=
t.get
return t.get

/-- Wait until any of the tasks in the given list has finished, then return its result. -/
@[extern "lean_io_wait_any"] constant waitAny : @& List (Task α) → IO α
Expand Down Expand Up @@ -395,16 +395,16 @@ constant metadata : @& FilePath → IO IO.FS.Metadata

def isDir (p : FilePath) : BaseIO Bool := do
match (← p.metadata.toBaseIO) with
| Except.ok m => m.type == IO.FS.FileType.dir
| Except.error _ => false
| Except.ok m => return m.type == IO.FS.FileType.dir
| Except.error _ => return false

def pathExists (p : FilePath) : BaseIO Bool := do
(← p.metadata.toBaseIO).toBool
def pathExists (p : FilePath) : BaseIO Bool :=
return (← p.metadata.toBaseIO).toBool

/--
Return all filesystem entries of a preorder traversal of all directories satisfying `enter`, starting at `p`.
Symbolic links are visited as well by default. -/
partial def walkDir (p : FilePath) (enter : FilePath → IO Bool := fun _ => true) : IO (Array FilePath) :=
partial def walkDir (p : FilePath) (enter : FilePath → IO Bool := fun _ => pure true) : IO (Array FilePath) :=
Prod.snd <$> StateT.run (go p) #[]
where
go p := do
Expand All @@ -421,7 +421,7 @@ where
if (← enter p) then
go p'
| FS.FileType.dir => go d.path
| _ => ()
| _ => return ()

end System.FilePath

Expand Down
2 changes: 1 addition & 1 deletion src/Lean/Attributes.lean
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def Attribute.erase (declName : Name) (attrName : Name) : AttrM Unit := do
@[export lean_update_env_attributes]
def updateEnvAttributesImpl (env : Environment) : IO Environment := do
let map ← attributeMapRef.get
let s attributeExtension.getState env
let s := attributeExtension.getState env
let s := map.foldl (init := s) fun s attrName attrImpl =>
if s.map.contains attrName then
s
Expand Down
18 changes: 9 additions & 9 deletions src/Lean/Data/Json/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -183,44 +183,44 @@ def isNull : Json -> Bool
| _ => false

def getObj? : Json → Except String (RBNode String (fun _ => Json))
| obj kvs => kvs
| obj kvs => return kvs
| _ => throw "object expected"

def getArr? : Json → Except String (Array Json)
| arr a => a
| arr a => return a
| _ => throw "array expected"

def getStr? : Json → Except String String
| str s => s
| str s => return s
| _ => throw "String expected"

def getNat? : Json → Except String Nat
| (n : Nat) => n
| (n : Nat) => return n
| _ => throw "Natural number expected"

def getInt? : Json → Except String Int
| (i : Int) => i
| (i : Int) => return i
| _ => throw "Integer expected"

def getBool? : Json → Except String Bool
| (b : Bool) => b
| (b : Bool) => return b
| _ => throw "Bool expected"

def getNum? : Json → Except String JsonNumber
| num n => n
| num n => return n
| _ => throw "number expected"

def getObjVal? : Json → String → Except String Json
| obj kvs, k =>
match kvs.find compare k with
| some v => v
| some v => return v
| none => throw s!"property not found: {k}"
| _ , _ => throw "object expected"

def getArrVal? : Json → Nat → Except String Json
| arr a, i =>
match a.get? i with
| some v => v
| some v => return v
| none => throw s!"index out of bounds: {i}"
| _ , _ => throw "array expected"

Expand Down
8 changes: 4 additions & 4 deletions src/Lean/Data/Json/FromToJson.lean
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ instance : FromJson Name where
if s == "[anonymous]" then
return Name.anonymous
else
let some n Syntax.decodeNameLit ("`" ++ s)
let some n := Syntax.decodeNameLit ("`" ++ s)
| throw s!"expected a `Name`, got '{j}'"
return n

Expand All @@ -92,7 +92,7 @@ instance : ToJson Name where
cannot represent 64-bit numbers. -/
def bignumFromJson? (j : Json) : Except String Nat := do
let s ← j.getStr?
let some v Syntax.decodeNatLitVal? s -- TODO maybe this should be in Std
let some v := Syntax.decodeNatLitVal? s -- TODO maybe this should be in Std
| throw s!"expected a string-encoded number, got '{j}'"
return v

Expand Down Expand Up @@ -122,8 +122,8 @@ instance : ToJson UInt64 where
namespace Json

instance : FromJson Structured := ⟨fun
| arr a => Structured.arr a
| obj o => Structured.obj o
| arr a => return Structured.arr a
| obj o => return Structured.obj o
| j => throw s!"expected structured object, got '{j}'"

instance : ToJson Structured := ⟨fun
Expand Down
Loading

0 comments on commit 12e2a79

Please sign in to comment.