@[inline]
def
Lean.checkCache
{α : Type}
{β : Type}
{m : Type → Type}
[Lean.MonadCache α β m]
[Monad m]
(a : α)
(f : Unit → m β)
:
m β
If entry a := b
is already in the cache, then return b
.
Otherwise, execute b ← f ()
, store a := b
in the cache and return b
.
Equations
- Lean.checkCache a f = do let __do_lift ← Lean.MonadCache.findCached? a match __do_lift with | some b => pure b | none => do let b ← f () Lean.MonadCache.cache a b pure b
Instances For
instance
Lean.instMonadCacheReaderT
{α : Type}
{β : Type}
{ρ : Type}
{m : Type → Type}
[Lean.MonadCache α β m]
:
Lean.MonadCache α β (ReaderT ρ m)
Equations
- Lean.instMonadCacheReaderT = { findCached? := fun (a : α) (x : ρ) => Lean.MonadCache.findCached? a, cache := fun (a : α) (b : β) (x : ρ) => Lean.MonadCache.cache a b }
@[always_inline]
instance
Lean.instMonadCacheExceptTOfMonad
{α : Type}
{β : Type}
{ε : Type}
{m : Type → Type}
[Lean.MonadCache α β m]
[Monad m]
:
Lean.MonadCache α β (ExceptT ε m)
Equations
- Lean.instMonadCacheExceptTOfMonad = { findCached? := fun (a : α) => ExceptT.lift (Lean.MonadCache.findCached? a), cache := fun (a : α) (b : β) => ExceptT.lift (Lean.MonadCache.cache a b) }
Adapter for implementing MonadCache
interface using HashMap
s.
We just have to specify how to extract/modify the HashMap
.
- getCache : m (Std.HashMap α β)
- modifyCache : (Std.HashMap α β → Std.HashMap α β) → m Unit
Instances
@[inline]
def
Lean.MonadHashMapCacheAdapter.findCached?
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadHashMapCacheAdapter α β m]
(a : α)
:
m (Option β)
Equations
- Lean.MonadHashMapCacheAdapter.findCached? a = do let c ← Lean.MonadHashMapCacheAdapter.getCache pure (c.get? a)
Instances For
@[inline]
def
Lean.MonadHashMapCacheAdapter.cache
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Lean.MonadHashMapCacheAdapter α β m]
(a : α)
(b : β)
:
m Unit
Equations
- Lean.MonadHashMapCacheAdapter.cache a b = Lean.MonadHashMapCacheAdapter.modifyCache fun (s : Std.HashMap α β) => s.insert a b
Instances For
instance
Lean.MonadHashMapCacheAdapter.instMonadCacheOfMonad
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadHashMapCacheAdapter α β m]
:
Lean.MonadCache α β m
Equations
- Lean.MonadHashMapCacheAdapter.instMonadCacheOfMonad = { findCached? := Lean.MonadHashMapCacheAdapter.findCached?, cache := Lean.MonadHashMapCacheAdapter.cache }
def
Lean.MonadCacheT
{ω : Type}
(α : Type)
(β : Type)
(m : Type → Type)
[STWorld ω m]
[BEq α✝]
[Hashable α✝]
(α : Type)
:
Equations
- Lean.MonadCacheT α β m = StateRefT' ω (Std.HashMap α β) m
Instances For
instance
Lean.MonadCacheT.instMonadHashMapCacheAdapter
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[MonadLiftT (ST ω) m]
:
Lean.MonadHashMapCacheAdapter α β (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadHashMapCacheAdapter = { getCache := get, modifyCache := fun (f : Std.HashMap α β → Std.HashMap α β) => modify f }
@[inline]
def
Lean.MonadCacheT.run
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[MonadLiftT (ST ω) m]
[Monad m]
{σ : Type}
(x : Lean.MonadCacheT α β m σ)
:
m σ
Equations
- x.run = StateRefT'.run' x Std.HashMap.empty
Instances For
instance
Lean.MonadCacheT.instMonad
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[Monad m]
:
Monad (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonad = inferInstanceAs (Monad (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instMonadLift
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
:
MonadLift m (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadLift = inferInstanceAs (MonadLift m (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instMonadExceptOf
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
(ε : Type u_1)
[MonadExceptOf ε m]
:
MonadExceptOf ε (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadExceptOf ε = inferInstanceAs (MonadExceptOf ε (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instMonadControl
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
:
MonadControl m (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadControl = inferInstanceAs (MonadControl m (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instMonadFinally
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[MonadFinally m]
:
MonadFinally (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadFinally = inferInstanceAs (MonadFinally (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instMonadRef
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[Lean.MonadRef m]
:
Lean.MonadRef (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instMonadRef = inferInstanceAs (Lean.MonadRef (StateRefT' ω (Std.HashMap α β) m))
instance
Lean.MonadCacheT.instAlternative
{ω : Type}
{α : Type}
{β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[Monad m]
[Alternative m]
:
Alternative (Lean.MonadCacheT α β m)
Equations
- Lean.MonadCacheT.instAlternative = inferInstanceAs (Alternative (StateRefT' ω (Std.HashMap α β) m))
def
Lean.MonadStateCacheT
(α : Type)
(β : Type)
(m : Type → Type)
[BEq α✝]
[Hashable α✝]
(α : Type)
:
Equations
- Lean.MonadStateCacheT α β m = StateT (Std.HashMap α β) m
Instances For
instance
Lean.MonadStateCacheT.instMonadHashMapCacheAdapter
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
Lean.MonadHashMapCacheAdapter α β (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonadHashMapCacheAdapter = { getCache := get, modifyCache := fun (f : Std.HashMap α β → Std.HashMap α β) => modify f }
@[inline]
def
Lean.MonadStateCacheT.run
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
{σ : Type}
(x : Lean.MonadStateCacheT α β m σ)
:
m σ
Equations
- x.run = StateT.run' x Std.HashMap.empty
Instances For
instance
Lean.MonadStateCacheT.instMonad
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
Monad (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonad = inferInstanceAs (Monad (StateT (Std.HashMap α β) m))
instance
Lean.MonadStateCacheT.instMonadLift
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
MonadLift m (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonadLift = inferInstanceAs (MonadLift m (StateT (Std.HashMap α β) m))
instance
Lean.MonadStateCacheT.instMonadExceptOf
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
(ε : Type u_1)
[MonadExceptOf ε m]
:
MonadExceptOf ε (Lean.MonadStateCacheT α β m)
Equations
instance
Lean.MonadStateCacheT.instMonadControl
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
MonadControl m (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonadControl = inferInstanceAs (MonadControl m (StateT (Std.HashMap α β) m))
instance
Lean.MonadStateCacheT.instMonadFinally
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[MonadFinally m]
:
MonadFinally (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonadFinally = inferInstanceAs (MonadFinally (StateT (Std.HashMap α β) m))
instance
Lean.MonadStateCacheT.instMonadRef
{α : Type}
{β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadRef m]
:
Lean.MonadRef (Lean.MonadStateCacheT α β m)
Equations
- Lean.MonadStateCacheT.instMonadRef = inferInstanceAs (Lean.MonadRef (StateT (Std.HashMap α β) m))