feat(library/init/control/monad): mark monadInhabited as an instance

This commit is contained in:
Leonardo de Moura 2019-05-20 09:33:17 -07:00
parent ff74b9f44a
commit 40ecbb7cbc
12 changed files with 2 additions and 25 deletions

View file

@ -27,11 +27,9 @@ class Monad (m : Type u → Type v) extends Applicative m, HasBind m : Type (max
(seqLeft := λ α β x y, x >>= λ a, y >>= λ _, pure a)
(seqRight := λ α β x y, x >>= λ _, y)
/- We do not add these instances by default because they are rarely needed,
and could slow down the current type class resolution procedure. -/
def monadInhabited {α : Type u} {m : Type u → Type v} [Monad m] [Inhabited α] : Inhabited (m α) :=
instance monadInhabited {α : Type u} {m : Type u → Type v} [Monad m] [Inhabited α] : Inhabited (m α) :=
⟨pure $ default _⟩
/- Alternative instance -/
def monadInhabited' {α : Type u} {m : Type u → Type v} [Monad m] : Inhabited (α → m α) :=
⟨pure⟩

View file

@ -172,8 +172,6 @@ miterate₂Aux a₁ a₂ f 0 b
@[inline] def mfoldl₂ (f : β → ασ → m β) (b : β) (a₁ : Array α) (a₂ : Array σ): m β :=
miterate₂ a₁ a₂ b (λ _ a₁ a₂ b, f b a₁ a₂)
local attribute [instance] monadInhabited
-- TODO(Leo): justify termination using wf-rec
@[specialize] partial def mfindAux (a : Array α) (f : α → m (Option β)) : Nat → m (Option β)
| i :=
@ -213,7 +211,6 @@ Id.run $ mfindAux a f 0
section
variables {m : Type → Type v} [Monad m]
local attribute [instance] monadInhabited
@[specialize] partial def anyMAux (a : Array α) (p : α → m Bool) : Nat → m Bool
| i :=
@ -307,7 +304,6 @@ as.foldl (λ bs a, bs.push (f a)) (mkEmpty as.size)
section
variables {m : Type u → Type u} [Monad m]
local attribute [instance] monadInhabited
@[specialize]
partial def mforAux {α : Type w} {β : Type u} (f : α → m β) (a : Array α) : Nat → m PUnit

View file

@ -45,8 +45,6 @@ let fmts := map.fold (λ fmt k ps,
instance : HasFormat ParamMap := ⟨ParamMap.fmt⟩
instance : HasToString ParamMap := ⟨λ m, Format.pretty (format m)⟩
local attribute [instance] monadInhabited
namespace InitParamMap
/- Mark parameters that take a reference as borrow -/

View file

@ -27,7 +27,6 @@ Assumptions:
- This transformation is applied after `reset` and `reuse` instructions have been added.
Reason: `resetreuse.lean` ignores `box` and `unbox` instructions.
-/
local attribute [instance] monadInhabited
/- Infer scrutinee type using `case` alternatives.
This can be done whenever `alts` does not contain an `Alt.default _` value. -/

View file

@ -72,8 +72,6 @@ do ctx ← read,
pure $ ctx.addParam p) ctx,
adaptReader (λ _, ctx) k
local attribute [instance] monadInhabited
partial def checkFnBody : FnBody → M Unit
| (FnBody.vdecl x t v b) := do
checkExpr t v,

View file

@ -12,7 +12,6 @@ import init.lean.compiler.ir.emitutil
namespace Lean
namespace IR
namespace EmitCpp
local attribute [instance] monadInhabited
def leanMainFn := "_lean_main"

View file

@ -11,7 +11,6 @@ import init.lean.compiler.ir.compilerm
namespace Lean
namespace IR
local attribute [instance] monadInhabited
namespace UsesLeanNamespace

View file

@ -46,8 +46,6 @@ abbrev M := State LocalContext
@[inline] def visitArgs (w : Index) (as : Array Arg) : M Bool := pure (HasIndex.visitArgs w as)
@[inline] def visitExpr (w : Index) (e : Expr) : M Bool := pure (HasIndex.visitExpr w e)
local attribute [instance] monadInhabited
partial def visitFnBody (w : Index) : FnBody → M Bool
| (FnBody.vdecl x _ v b) := visitExpr w v <||> visitFnBody b
| (FnBody.jdecl j ys v b) := visitFnBody v <||> visitFnBody b

View file

@ -22,8 +22,6 @@ do found ← get,
def checkParams (ps : Array Param) : M Bool :=
ps.allM $ λ p, checkId p.x.idx
local attribute [instance] monadInhabited
partial def checkFnBody : FnBody → M Bool
| (FnBody.vdecl x _ _ b) := checkId x.idx <&&> checkFnBody b
| (FnBody.jdecl j ys _ b) := checkId j.idx <&&> checkParams ys <&&> checkFnBody b
@ -99,8 +97,6 @@ abbrev N := ReaderT IndexRenaming (State Nat)
instance MtoN {α} : HasCoe (M α) (N α) :=
⟨λ x m, pure $ x m⟩
local attribute [instance] monadInhabited
partial def normFnBody : FnBody → N FnBody
| (FnBody.vdecl x t v b) := do v ← normExpr v, withVar x $ λ x, FnBody.vdecl x t v <$> normFnBody b
| (FnBody.jdecl j ys v b) := do

View file

@ -15,8 +15,6 @@ namespace ExplicitRC
that introduce the instructions `release` and `set`
-/
local attribute [instance] monadInhabited
structure VarInfo :=
(ref : Bool := true) -- true if the variable may be a reference (aka pointer) at runtime
(persistent : Bool := false) -- true if the variable is statically known to be marked a Persistent at runtime

View file

@ -56,7 +56,6 @@ private partial def S (w : VarId) (c : CtorInfo) : FnBody → FnBody
/- We use `Context` to track join points in scope. -/
abbrev M := ReaderT LocalContext (StateT Index Id)
local attribute [instance] monadInhabited
private def mkFresh : M VarId :=
do idx ← getModify (+1),

View file

@ -127,7 +127,6 @@ def isOfKind (k : SyntaxNodeKind) : Syntax → Bool
section
variables {m : Type → Type} [Monad m] (r : Syntax → m (Option Syntax))
local attribute [instance] monadInhabited
partial def mreplace : Syntax → m Syntax
| stx@(rawNode n) := do