Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/693343d7-a38c-8012-a67c-11cbed4c0fd9
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== I provide two parts: === * existence proof for a Reader R distributive law (under parametricity / product-like O), and * exposition showing State commonly handled by using StateT (monad transformer) rather than a distributive law when semantics diverge. ==== Goal: construct λ_A : Reader R (O A) = (R -> O A) ⇒ O (R -> A) = O (Reader R A) natural in A and satisfy Beck conditions. ==== ===== We need that O is parametric in the sense that there is a canonical iso: ===== <syntaxhighlight>O (R -> A) ≅ (R -> O A) </syntaxhighlight> for all A — i.e., O commutes with products/exponentials for constant R. This holds if O is defined polynomially / functorially with no dependence on R, e.g., Tree built from A and finite lists: For Tree(A): <syntaxhighlight>Tree (R -> A) ≅ R -> Tree A </syntaxhighlight> ? Not strictly isomorphic in general, but if Tree is built from A in strictly covariant positions, function-space commutation requires parametricity/uniformity. However there is a natural map: <syntaxhighlight>φ_A : (R -> Tree A) -> Tree (R -> A) </syntaxhighlight> constructed by mapping a function F : R -> Tree A to a Tree (R -> A) that at each leaf yields the function r ↦ value at leaf — this requires exchanging quantifiers and may not be an iso unless Tree is finitary and R is discrete. ===== If O commutes with R -> -, then define λ_A := φ_A^{-1} (the inverse iso). Then show Beck diagrams: ===== * λ ∘ η = η and * λ ∘ μ = μ ∘ O λ ∘ λ (compatibility with multiplication) These hold by naturality and functoriality of φ (given iso). Hence Reader distributes. ===== In practice: ===== * For many useful O implementations (e.g., Tree with finite branching and when R is finite or discrete), one can construct λ concretely. * When O is parametric or product-preserving, Reader distributes. If not, use ReaderT/OT transformer. ==== For State S the desired distributive law λ : State S ∘ O ⇒ O ∘ State S would be: ==== <syntaxhighlight>λ_A : (S -> (O A × S)) -> O (S -> (A × S)) </syntaxhighlight> This requires pushing state inside the O structure. Two natural semantics: # Shared-state semantics: meta-levels and base-level share one global S. That is, O computations access the same S. If the O structure is such that we can push s into each leaf and reconstruct, an appropriate λ may exist. For Tree, one could attempt: ``<code> λ (h : S -> (Tree A × S)) := Node MergeOp [ ... ] ??? </code>`` but in general coordinating the threaded state across branching Node requires design decisions (how nodes interleave, whether branches run in sequence or in parallel, whether to merge resulting states). # Isolated-state semantics (practical): prefer StateT S O or O applied over State depending on semantics: - StateT S O A := S -> O (A × S) — meta-runner with global state threaded inside O. - O (State S A) := O (S -> (A × S)) — meta-structures each have stateful computations as leaves. Hence, instead of proving existence of λ in general, the practical engineering solution is to stack monads with StateT or State transformer and choose composition according to desired semantics. This is the standard pattern in applicative/monad transformer design (Haskell-style). If you want a formal distributive law existence proof for a particular O and a chosen state semantics, give me O concretely (e.g., this Tree with merge semantics) and I’ll build/verify λ.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)