@@ -13950,11 +13950,84 @@ noprefix "false"
13950
13950
\end_inset
13951
13951
13952
13952
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
13954
14015
or system.
13955
14016
It is not obvious in advance what operations will be useful or necessary
13956
14017
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
13958
14031
\begin_inset listings
13959
14032
inline true
13960
14033
status open
@@ -13966,18 +14039,17 @@ Either
13966
14039
13967
14040
\end_inset
13968
14041
13969
- monad?) So, different libraries choose different sets of supported operations.
14042
+ monad?) Different libraries choose different sets of supported operations.
13970
14043
However, adding a new operation to a monad in an MTL-style library requires
13971
14044
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.
13974
14046
\end_layout
13975
14047
13976
14048
\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
13981
14053
\begin_inset Formula $L^{A}$
13982
14054
\end_inset
13983
14055
@@ -13986,7 +14058,7 @@ The third problem is the difficulty in lifting certain operations to certain
13986
14058
\end_inset
13987
14059
13988
14060
.
13989
- Operations of these types are lifted from the monad
14061
+ All operations of this form are lifted from the monad
13990
14062
\begin_inset Formula $L$
13991
14063
\end_inset
13992
14064
@@ -13999,7 +14071,9 @@ The third problem is the difficulty in lifting certain operations to certain
13999
14071
\end_inset
14000
14072
14001
14073
.
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
14003
14077
\begin_inset listings
14004
14078
inline true
14005
14079
status open
@@ -14027,8 +14101,7 @@ Reader
14027
14101
\begin_inset Formula $R\rightarrow\text{Reader}^{R,A}\rightarrow\text{Reader}^{R,A}$
14028
14102
\end_inset
14029
14103
14030
- .
14031
- Because some
14104
+ where some some
14032
14105
\begin_inset listings
14033
14106
inline true
14034
14107
status open
@@ -14041,7 +14114,49 @@ Reader
14041
14114
\end_inset
14042
14115
14043
14116
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
14045
14160
\begin_inset listings
14046
14161
inline true
14047
14162
status open
@@ -14057,19 +14172,15 @@ withEnv
14057
14172
\begin_inset Formula $P^{A}$
14058
14173
\end_inset
14059
14174
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
+ .
14065
14176
Lifting
14066
14177
\begin_inset listings
14067
14178
inline true
14068
14179
status open
14069
14180
14070
14181
\begin_layout Plain Layout
14071
14182
14072
- withEnv
14183
+ clear
14073
14184
\end_layout
14074
14185
14075
14186
\end_inset
@@ -14097,14 +14208,18 @@ status open
14097
14208
14098
14209
\begin_layout Plain Layout
14099
14210
14100
- State
14211
+ Writer
14101
14212
\end_layout
14102
14213
14103
14214
\end_inset
14104
14215
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
14108
14223
\end_layout
14109
14224
14110
14225
\begin_layout Standard
0 commit comments