Skip to content

Commit abbe0e4

Browse files
author
sergei.winitzki
committed
wip MTL subsection
1 parent 54de5b2 commit abbe0e4

File tree

1 file changed

+139
-24
lines changed

1 file changed

+139
-24
lines changed

sofp-src/sofp-transformers.lyx

Lines changed: 139 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13950,11 +13950,84 @@ noprefix "false"
1395013950
\end_inset
1395113951

1395213952
summarizes various effectful operations for some well-known monads.
13953-
The choice of operations appears to be random, not following any principle
13953+
\begin_inset Foot
13954+
status open
13955+
13956+
\begin_layout Plain Layout
13957+
The table was compiled using the
13958+
\family typewriter
13959+
cats-mtl
13960+
\family default
13961+
documentation and the papers
13962+
\begin_inset Quotes eld
13963+
\end_inset
13964+
13965+
13966+
\emph on
13967+
Monad transformers and modular interpreters
13968+
\emph default
13969+
13970+
\begin_inset Quotes erd
13971+
\end_inset
13972+
13973+
(see
13974+
\family typewriter
13975+
13976+
\begin_inset CommandInset href
13977+
LatexCommand href
13978+
target "http://web.cecs.pdx.edu/~mpj/pubs/modinterp.html"
13979+
literal "false"
13980+
13981+
\end_inset
13982+
13983+
13984+
\family default
13985+
) and
13986+
\begin_inset Quotes eld
13987+
\end_inset
13988+
13989+
13990+
\emph on
13991+
Modular monad transformers
13992+
\emph default
13993+
13994+
\begin_inset Quotes erd
13995+
\end_inset
13996+
13997+
(see
13998+
\family typewriter
13999+
14000+
\begin_inset CommandInset href
14001+
LatexCommand href
14002+
target "https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.219.5365"
14003+
literal "false"
14004+
14005+
\end_inset
14006+
14007+
14008+
\family default
14009+
).
14010+
\end_layout
14011+
14012+
\end_inset
14013+
14014+
The choice of operations appears to be heuristic, not following any principle
1395414015
or system.
1395514016
It is not obvious in advance what operations will be useful or necessary
1395614017
in practical tasks involving a given monad.
13957-
(Do we need an extra filtering operation for the
14018+
(Do we need a
14019+
\begin_inset listings
14020+
inline true
14021+
status open
14022+
14023+
\begin_layout Plain Layout
14024+
14025+
filter
14026+
\end_layout
14027+
14028+
\end_inset
14029+
14030+
operation for the
1395814031
\begin_inset listings
1395914032
inline true
1396014033
status open
@@ -13966,18 +14039,17 @@ Either
1396614039

1396714040
\end_inset
1396814041

13969-
monad?) So, different libraries choose different sets of supported operations.
14042+
monad?) Different libraries choose different sets of supported operations.
1397014043
However, adding a new operation to a monad in an MTL-style library requires
1397114044
rewriting the typeclasses involving that monad.
13972-
Users of the library who cannot modify the library code will be unable
13973-
to add new operations.
14045+
Users who cannot modify the library code will be unable to add new operations.
1397414046
\end_layout
1397514047

1397614048
\begin_layout Standard
13977-
The third problem is the difficulty in lifting certain operations to certain
13978-
monad transformers.
13979-
So far, the examples in this subsection were limited to effectful operations
13980-
with type signatures of the form
14049+
The third problem is the lack of a general method of lifting effectful operation
14050+
s to arbitrary monad transformers.
14051+
So far, the examples in this subsection were limited to operations with
14052+
type signatures of the form
1398114053
\begin_inset Formula $L^{A}$
1398214054
\end_inset
1398314055

@@ -13986,7 +14058,7 @@ The third problem is the difficulty in lifting certain operations to certain
1398614058
\end_inset
1398714059

1398814060
.
13989-
Operations of these types are lifted from the monad
14061+
All operations of this form are lifted from the monad
1399014062
\begin_inset Formula $L$
1399114063
\end_inset
1399214064

@@ -13999,7 +14071,9 @@ The third problem is the difficulty in lifting certain operations to certain
1399914071
\end_inset
1400014072

1400114073
.
14002-
However, an operation called
14074+
However, some operations have significantly different type signatures and
14075+
cannot be lifted to arbtirary monad stacks by composing with a lift function.
14076+
For instance, an operation called
1400314077
\begin_inset listings
1400414078
inline true
1400514079
status open
@@ -14027,8 +14101,7 @@ Reader
1402714101
\begin_inset Formula $R\rightarrow\text{Reader}^{R,A}\rightarrow\text{Reader}^{R,A}$
1402814102
\end_inset
1402914103

14030-
.
14031-
Because some
14104+
where some some
1403214105
\begin_inset listings
1403314106
inline true
1403414107
status open
@@ -14041,7 +14114,49 @@ Reader
1404114114
\end_inset
1404214115

1404314116
monad values are used as arguments in that type signature (that is, in
14044-
a contravariant position), it is impossible to lift the operation
14117+
a contravariant position).
14118+
The withEnv operation cannot be lifted to a function of type
14119+
\begin_inset Formula $R\rightarrow P^{A}\rightarrow P^{A}$
14120+
\end_inset
14121+
14122+
by using only a lift function
14123+
\begin_inset Formula $p:\text{Reader}^{R,A}\rightarrow P^{A}$
14124+
\end_inset
14125+
14126+
.
14127+
Similarly, the
14128+
\begin_inset listings
14129+
inline true
14130+
status open
14131+
14132+
\begin_layout Plain Layout
14133+
14134+
clear
14135+
\end_layout
14136+
14137+
\end_inset
14138+
14139+
operation for the
14140+
\begin_inset listings
14141+
inline true
14142+
status open
14143+
14144+
\begin_layout Plain Layout
14145+
14146+
Writer
14147+
\end_layout
14148+
14149+
\end_inset
14150+
14151+
monad has type signature
14152+
\begin_inset Formula $\text{Writer}^{W,A}\rightarrow\text{Writer}^{W,A}$
14153+
\end_inset
14154+
14155+
and cannot be lifted to
14156+
\begin_inset Formula $P^{A}\rightarrow P^{A}$
14157+
\end_inset
14158+
14159+
***cle it is impossible to lift the operation
1404514160
\begin_inset listings
1404614161
inline true
1404714162
status open
@@ -14057,19 +14172,15 @@ withEnv
1405714172
\begin_inset Formula $P^{A}$
1405814173
\end_inset
1405914174

14060-
by using only a lift function
14061-
\begin_inset Formula $p:\text{Reader}^{R,A}\rightarrow P^{A}$
14062-
\end_inset
14063-
14064-
.
14175+
.
1406514176
Lifting
1406614177
\begin_inset listings
1406714178
inline true
1406814179
status open
1406914180

1407014181
\begin_layout Plain Layout
1407114182

14072-
withEnv
14183+
clear
1407314184
\end_layout
1407414185

1407514186
\end_inset
@@ -14097,14 +14208,18 @@ status open
1409714208

1409814209
\begin_layout Plain Layout
1409914210

14100-
State
14211+
Writer
1410114212
\end_layout
1410214213

1410314214
\end_inset
1410414215

14105-
, needs code written specifically for that combination of monads.
14106-
The required code length becomes quadratic in the number of supported monads.
14107-
14216+
***, needs code written specifically for that combination of monads.
14217+
The length of required custom code is quadratic in the number of supported
14218+
monads and linear in the number of operations.
14219+
\end_layout
14220+
14221+
\begin_layout Standard
14222+
As an example, consider lifting withEnv to the stack
1410814223
\end_layout
1410914224

1411014225
\begin_layout Standard

0 commit comments

Comments
 (0)