The areas / V33. Data structures and computation
Mathlib.Control.ULiftable
31 declarations. Mathlib docs · Source
Universe lifting for type families
Some functors such as Option and List are universe polymorphic. Unlike
type polymorphism where Option α is a function application and reasoning and
generalizations that apply to functions can be used, Option.{u} and Option.{v}
are not one function applied to two universe names but one polymorphic definition
instantiated twice. This means that whatever works on Option.{u} is hard
to transport over to Option.{v}. ULiftable is an attempt at improving the situation.
ULiftable Option.{u} Option.{v} gives us a generic and composable way to use
Option.{u} in a context that requires Option.{v}. It is often used in tandem with
ULift but the two are purposefully decoupled.
Main definitions
ULiftableclass
Tags
universe polymorphism functor
def ULiftable.ctorIdx E1 #
{f : outParam (Type u₀ → Type u₁)} → {g : Type v₀ → Type v₁} → ULiftable f g → ℕ
class ULiftable E3 #
outParam (Type u₀ → Type u₁) → (Type v₀ → Type v₁) → Type (max (max (max (u₀ + 1) u₁) (v₀ + 1)) v₁)
Given a universe polymorphic type family M.{u} : Type u₁ → Type u₂, this class convert between instantiations, from
M.{u} : Type u₁ → Type u₂ to M.{v} : Type v₁ → Type v₂ and back.
f is an outParam, because g can almost always be inferred from the current monad.
At any rate, the lift should be unique, as the intent is to only lift the same constants with
different universe parameters.
ctor ULiftable.mk E0 #
{f : outParam (Type u₀ → Type u₁)} →
{g : Type v₀ → Type v₁} → ({α : Type u₀} → {β : Type v₀} → α ≃ β → f α ≃ g β) → ULiftable f g
abbrev ULiftable.congr E1 #
{f : outParam (Type u₀ → Type u₁)} →
{g : Type v₀ → Type v₁} → [self : ULiftable f g] → {α : Type u₀} → {β : Type v₀} → α ≃ β → f α ≃ g β
abbrev ULiftable.symm E1 #
(f : Type u₀ → Type u₁) → (g : Type v₀ → Type v₁) → [ULiftable f g] → ULiftable g f
Not an instance as it is incompatible with outParam. In practice it seems not to be needed
anyway.
instance ULiftable.refl E0 #
(f : Type u₀ → Type u₁) → [inst : Functor f] → [LawfulFunctor f] → ULiftable f f
abbrev ULiftable.up E1 #
{f : Type u₀ → Type u₁} → {g : Type (max u₀ v) → Type v₁} → [ULiftable f g] → {α : Type u₀} → f α → g (ULift.{v, u₀} α)
The most common practical use ULiftable (together with down), the function up.{v} takes
x : M.{u} α and lifts it to M.{max u v} (ULift.{v} α)
abbrev ULiftable.down E1 #
{f : Type u₀ → Type u₁} → {g : Type (max u₀ v) → Type v₁} → [ULiftable f g] → {α : Type u₀} → g (ULift.{v, u₀} α) → f α
The most common practical use of ULiftable (together with up), the function down.{v} takes
x : M.{max u v} (ULift.{v} α) and lowers it to M.{u} α
def ULiftable.adaptUp E1 #
(F : Type v₀ → Type v₁) →
(G : Type (max v₀ u₀) → Type u₁) →
[ULiftable F G] → [Monad G] → {α : Type v₀} → {β : Type (max v₀ u₀)} → F α → (α → G β) → G β
convenient shortcut to avoid manipulating ULift
def ULiftable.adaptDown E1 #
{F : Type (max u₀ v₀) → Type u₁} →
{G : Type v₀ → Type v₁} →
[L : ULiftable G F] → [Monad F] → {α : Type (max u₀ v₀)} → {β : Type v₀} → F α → (α → G β) → G β
convenient shortcut to avoid manipulating ULift
def ULiftable.upMap E1 #
{F : Type u₀ → Type u₁} →
{G : Type (max u₀ v₀) → Type v₁} →
[ULiftable F G] → [Functor G] → {α : Type u₀} → {β : Type (max u₀ v₀)} → (α → β) → F α → G β
map function that moves up universes
def ULiftable.downMap E1 #
{F : Type (max u₀ v₀) → Type u₁} →
{G : Type u₀ → Type v₁} → [ULiftable G F] → [Functor F] → {α : Type (max u₀ v₀)} → {β : Type u₀} → (α → β) → F α → G β
map function that moves down universes
abbrev ULiftable.up' E1 #
{f : Type u₀ → Type u₁} → {g : Type v₀ → Type v₁} → [ULiftable f g] → f PUnit.{u₀ + 1} → g PUnit.{v₀ + 1}
A version of up for a PUnit return type.
abbrev ULiftable.down' E1 #
{f : Type u₀ → Type u₁} → {g : Type v₀ → Type v₁} → [ULiftable f g] → g PUnit.{v₀ + 1} → f PUnit.{u₀ + 1}
A version of down for a PUnit return type.
theorem ULiftable.up_down E1 #
∀ {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [inst : ULiftable f g] {α : Type u₀}
(x : g (ULift.{v₀, u₀} α)), ULiftable.up (ULiftable.down x) = x
theorem ULiftable.down_up E1 #
∀ {f : Type u₀ → Type u₁} {g : Type (max u₀ v₀) → Type v₁} [inst : ULiftable f g] {α : Type u₀} (x : f α),
ULiftable.down (ULiftable.up x) = x
instance instULiftableId E0 #
ULiftable Id Id
def StateT.uliftable' E1 #
{s : Type u₀} →
{s' : Type u₁} →
{m : Type u₀ → Type v₀} →
{m' : Type u₁ → Type v₁} → [ULiftable m m'] → s ≃ s' → ULiftable (StateT s m) (StateT s' m')
for specific state types, this function helps to create a uliftable instance
instance instULiftableStateTULift E0 #
{s : Type u₀} →
{m : Type u₀ → Type u_5} →
{m' : Type (max u₀ u_6) → Type u_7} → [ULiftable m m'] → ULiftable (StateT s m) (StateT (ULift.{u_6, u₀} s) m')
instance StateT.instULiftableULiftULift E0 #
{s : Type u₀} →
{m : Type (max u₀ v₀) → Type u_5} →
{m' : Type (max u₀ v₁) → Type u_6} →
[ULiftable m m'] → ULiftable (StateT (ULift.{max v₀ u₀, u₀} s) m) (StateT (ULift.{max v₁ u₀, u₀} s) m')
def ReaderT.uliftable' E1 #
{s : Type u₀} →
{s' : Type u₁} →
{m : Type u₀ → Type u_5} →
{m' : Type u₁ → Type u_6} → [ULiftable m m'] → s ≃ s' → ULiftable (ReaderT s m) (ReaderT s' m')
for specific reader monads, this function helps to create a uliftable instance
instance instULiftableReaderTULift E0 #
{s : Type u₀} →
{m : Type u₀ → Type u_5} →
{m' : Type (max u₀ u_6) → Type u_7} → [ULiftable m m'] → ULiftable (ReaderT s m) (ReaderT (ULift.{u_6, u₀} s) m')
instance ReaderT.instULiftableULiftULift E0 #
{s : Type u₀} →
{m : Type (max u₀ v₀) → Type u_5} →
{m' : Type (max u₀ v₁) → Type u_6} →
[ULiftable m m'] → ULiftable (ReaderT (ULift.{max v₀ u₀, u₀} s) m) (ReaderT (ULift.{max v₁ u₀, u₀} s) m')
def ContT.uliftable' E1 #
{r : Type u_1} →
{r' : Type u_2} →
{m : Type u_1 → Type u_5} →
{m' : Type u_2 → Type u_6} → [ULiftable m m'] → r ≃ r' → ULiftable (ContT r m) (ContT r' m')
for specific continuation passing monads, this function helps to create a uliftable instance
instance instULiftableContTULift E0 #
{s : Type u_5} →
{m : Type u_5 → Type u_6} →
{m' : Type (max u_5 u_7) → Type u_8} → [ULiftable m m'] → ULiftable (ContT s m) (ContT (ULift.{u_7, u_5} s) m')
instance ContT.instULiftableULiftULift E0 #
{s : Type u₀} →
{m : Type (max u₀ v₀) → Type u_5} →
{m' : Type (max u₀ v₁) → Type u_6} →
[ULiftable m m'] → ULiftable (ContT (ULift.{max v₀ u₀, u₀} s) m) (ContT (ULift.{max v₁ u₀, u₀} s) m')
def WriterT.uliftable' E1 #
{w : Type u_3} →
{w' : Type u_4} →
{m : Type u_3 → Type u_5} →
{m' : Type u_4 → Type u_6} → [ULiftable m m'] → w ≃ w' → ULiftable (WriterT w m) (WriterT w' m')
for specific writer monads, this function helps to create a uliftable instance
instance instULiftableWriterTULift E0 #
{s : Type u₀} →
{m : Type u₀ → Type u_5} →
{m' : Type (max u₀ u_6) → Type u_7} → [ULiftable m m'] → ULiftable (WriterT s m) (WriterT (ULift.{u_6, u₀} s) m')
instance WriterT.instULiftableULiftULift E0 #
{s : Type u₀} →
{m : Type (max u₀ v₀) → Type u_5} →
{m' : Type (max u₀ v₁) → Type u_6} →
[ULiftable m m'] → ULiftable (WriterT (ULift.{max v₀ u₀, u₀} s) m) (WriterT (ULift.{max v₁ u₀, u₀} s) m')
instance Except.instULiftable E0 #
{ε : Type u₀} → ULiftable (Except ε) (Except ε)
instance Option.instULiftable E0 #
ULiftable Option Option