@[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)
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}
{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}
{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}
{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 }
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)
Equations
- Lean.MonadCacheT.instMonadHashMapCacheAdapter = { getCache := get, modifyCache := fun (f : Std.HashMap α β → Std.HashMap α β) => modify f }
@[inline]
def
Lean.MonadCacheT.run
{ω α β : 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}
{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)
Equations
- Lean.MonadCacheT.instMonadLift = inferInstanceAs (MonadLift m (StateRefT' ω (Std.HashMap α β) 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)
Equations
- Lean.MonadCacheT.instMonadControl = inferInstanceAs (MonadControl m (StateRefT' ω (Std.HashMap α β) 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)
Equations
- Lean.MonadCacheT.instAlternative = inferInstanceAs (Alternative (StateRefT' ω (Std.HashMap α β) m))
Equations
- Lean.MonadStateCacheT α β m = StateT (Std.HashMap α β) m
Instances For
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 σ
Equations
- x.run = StateT.run' x Std.HashMap.empty
Instances For
instance
Lean.MonadStateCacheT.instMonad
{α β : 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}
{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}
{m : Type → Type}
[BEq α]
[Hashable α]
[Monad m]
(ε : Type u_1)
[MonadExceptOf ε m]
:
MonadExceptOf ε (Lean.MonadStateCacheT α β m)
Equations
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)
Equations
- Lean.MonadStateCacheT.instMonadFinally = inferInstanceAs (MonadFinally (StateT (Std.HashMap α β) m))
instance
Lean.MonadStateCacheT.instMonadRef
{α β : 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))