refactor: lake: use modifyGet in StoreInsts (#13517)
This PR uses `modifyGet` in the Lake's `MonadStore` instances, which is better for projecting the state of a `StateRefT`.
This commit is contained in:
parent
848122d1f9
commit
5637b3374c
2 changed files with 6 additions and 8 deletions
|
|
@ -9,8 +9,6 @@ prelude
|
|||
public import Init.Prelude
|
||||
import Init.Tactics
|
||||
|
||||
namespace Lake
|
||||
|
||||
opaque POpaque.nonemptyType.{u} : NonemptyType.{u}
|
||||
|
||||
/-- An value of unknown type in a specific universe. -/
|
||||
|
|
|
|||
|
|
@ -16,27 +16,27 @@ open Lean
|
|||
namespace Lake
|
||||
|
||||
public instance {cmp : κ → κ → Ordering} [Monad m] [Std.LawfulEqCmp cmp] : MonadDStore κ β (StateT (Std.DTreeMap κ β cmp) m) where
|
||||
fetch? k := return (← get).get? k
|
||||
fetch? k := modifyGet fun m => (m.get? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance {cmp : κ → κ → Ordering} [MonadLiftT (ST ω) m] [Monad m] [Std.LawfulEqCmp cmp] : MonadDStore κ β (StateRefT' ω (Std.DTreeMap κ β cmp) m) where
|
||||
fetch? k := return (← get).get? k
|
||||
fetch? k := modifyGet fun m => (m.get? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance [Monad m] : MonadStore κ α (StateT (RBArray κ α cmp) m) where
|
||||
fetch? k := return (← get).find? k
|
||||
fetch? k := modifyGet fun m => (m.find? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance [MonadLiftT (ST ω) m] [Monad m] : MonadStore κ α (StateRefT' ω (RBArray κ α cmp) m) where
|
||||
fetch? k := return (← get).find? k
|
||||
fetch? k := modifyGet fun m => (m.find? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance [Monad m] : MonadStore Name α (StateT (NameMap α) m) where
|
||||
fetch? k := return (← get).find? k
|
||||
fetch? k := modifyGet fun m => (m.find? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance [MonadLiftT (ST ω) m] [Monad m] : MonadStore Name α (StateRefT' ω (NameMap α) m) where
|
||||
fetch? k := return (← get).find? k
|
||||
fetch? k := modifyGet fun m => (m.find? k, m)
|
||||
store k a := modify (·.insert k a)
|
||||
|
||||
public instance [MonadDStore κ β m] [t : FamilyOut β k α] : MonadStore1Of k α m where
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue