Idiom
Idiom
Idiom
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Functional pearl 15<br />
Use the MFunctor laws and the above definition of ι to prove the equation<br />
fmap swap (ι x ⋆ u) = u ⋆ ι x<br />
for the function<br />
swap :: (a, b) → (b, a)<br />
swap (a, b) = (b, a)<br />
The proof makes essential use of higher-order functions.<br />
9.1 Strong lax monoidal functors<br />
In the first-order language of category theory, such data flow must be explicitly<br />
plumbed using strong functors, i.e. functors F equipped with a tensorial strength<br />
tAB : A × F B −→ F (A × B)<br />
that makes the following diagrams commute.<br />
1 × F A ∼ ⏐ = FA ⏐ <br />
t⏐<br />
<br />
<br />
F (1 × A) ∼ = F A<br />
(A × B) × F C ∼ = A × (B ⏐×<br />
F C)<br />
<br />
⏐<br />
<br />
⏐<br />
<br />
A × t<br />
<br />
<br />
t<br />
<br />
A × F (B × C)<br />
⏐<br />
⏐<br />
⏐<br />
⏐<br />
⏐<br />
⏐<br />
<br />
t F ((A × B) × C) ∼ = F (A × (B × C))<br />
The naturality axiom above then becomes strong naturality: the natural transformation<br />
m corresponding to ‘⋆’ must also respect the strength:<br />
(A × B) × (F C × F D) ∼ ⏐<br />
= (A × F C) × ⏐ (B × F D)<br />
⏐<br />
⏐<br />
(A × B) × m⏐<br />
⏐<br />
<br />
t × t<br />
(A × B) × ⏐F<br />
(C × D) F (A × C) × ⏐ F (B × D)<br />
⏐<br />
⏐<br />
t⏐<br />
⏐<br />
<br />
m F ((A × B) × (C × D)) ∼ = F ((A × C) × (B × D))<br />
Note that B and F C swap places in the above diagram: strong naturality implies<br />
commutativity with pure computations.<br />
Thus in categorical terms idioms are strong lax monoidal functors. Every strong<br />
monad determines two such functors, as the definition is symmetrical.<br />
10 Conclusions and further work<br />
References<br />
Baars, A.I., Löh, A., & Swierstra, S.D. (2004). Parsing permutation phrases. Journal of<br />
functional programming, 14(6), 635–646.<br />
Barr, Michael, & Wells, Charles. (1984). Toposes, triples and theories. Grundlehren der<br />
Mathematischen Wissenschaften, no. 278. New York: Springer. Chap. 9.