@[inline]
def
Lean.checkCache
{α β : 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}
{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}
{m : Type → Type}
[Lean.MonadCache α β m]
[Monad m]
:
Lean.MonadCache α β (ExceptT ε m)
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}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadHashMapCacheAdapter α β m]
(a : α)
:
m (Option β)
Instances For
@[inline]
def
Lean.MonadHashMapCacheAdapter.cache
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Lean.MonadHashMapCacheAdapter α β m]
(a : α)
(b : β)
:
m Unit
Instances For
instance
Lean.MonadHashMapCacheAdapter.instMonadCacheOfMonad
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadHashMapCacheAdapter α β m]
:
Lean.MonadCache α β m
Equations
- Lean.MonadCacheT α β m = StateRefT' ω (Std.HashMap α β) m
Instances For
instance
Lean.MonadCacheT.instMonadHashMapCacheAdapter
{ω α β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[MonadLiftT (ST ω) m]
:
Lean.MonadHashMapCacheAdapter α β (Lean.MonadCacheT α β m)
@[inline]
def
Lean.MonadCacheT.run
{ω α β : Type}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[MonadLiftT (ST ω) m]
[Monad m]
{σ : Type}
(x : Lean.MonadCacheT α β m σ)
:
m σ
Instances For
instance
Lean.MonadCacheT.instMonad
{ω α β : 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}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
:
MonadLift m (Lean.MonadCacheT α β m)
instance
Lean.MonadCacheT.instMonadExceptOf
{ω α β : 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}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
:
MonadControl m (Lean.MonadCacheT α β m)
instance
Lean.MonadCacheT.instMonadFinally
{ω α β : 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}
{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}
{m : Type → Type}
[STWorld ω m]
[BEq α]
[Hashable α]
[Monad m]
[Alternative m]
:
Alternative (Lean.MonadCacheT α β m)
instance
Lean.MonadStateCacheT.instMonadHashMapCacheAdapter
{α β : 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}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
{σ : Type}
(x : Lean.MonadStateCacheT α β m σ)
:
m σ
Instances For
instance
Lean.MonadStateCacheT.instMonad
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
Monad (Lean.MonadStateCacheT α β m)
instance
Lean.MonadStateCacheT.instMonadLift
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
:
MonadLift m (Lean.MonadStateCacheT α β m)
instance
Lean.MonadStateCacheT.instMonadExceptOf
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
(ε : Type u_1)
[MonadExceptOf ε m]
:
MonadExceptOf ε (Lean.MonadStateCacheT α β m)
instance
Lean.MonadStateCacheT.instMonadControl
{α β : 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}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[MonadFinally m]
:
MonadFinally (Lean.MonadStateCacheT α β m)
instance
Lean.MonadStateCacheT.instMonadRef
{α β : Type}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
[Lean.MonadRef m]
:
Lean.MonadRef (Lean.MonadStateCacheT α β m)