Effect: Difference between revisions

write just a little bit more
(initial article)
 
(write just a little bit more)
 
Line 5: Line 5:
== Examples from programming ==
== Examples from programming ==
Let's consider possible "side effects" of a function A → B. It might...
Let's consider possible "side effects" of a function A → B. It might...
* <span style="color:green">throw an error of type Err</span> instead of actually returning a result of type B.
* <mark>throw an error of type Err</mark> instead of actually returning a result of type B.
* <span style="color:green">return some "log" data</span> alongside its result of type B.
* <mark>return some "log" data</mark> alongside its result of type B.
* <span style="color:green">depend on / read some "environment" data</span> in order to produce a result of type B.
* <mark>depend on / read some "environment" data</mark> in order to produce a result of type B.


One way a programming language can encode this is using '''monads'''. Basically, we say we have functions of types like
One way a programming language can encode this is using '''monads'''. Basically, we say we have functions of types like


* A → <span style="color:green">Either Err</span> B
* A → <mark>Either Err</mark> B
* A → <span style="color:green">Writer Log</span> B
* A → <mark>Writer Log</mark> B
* A → <span style="color:green">Reader Env</span> B
* A → <mark>Reader Env</mark> B


and we rely on some way to ''compose'' these functions, while ''propagating'' their effects.
and we rely on some way to ''compose'' these functions, while ''propagating'' their effects.
Line 24: Line 24:


== In syntax ==
== In syntax ==
It turns out that we can extend this concept to syntax. For example, consider a [[noun phrase]] with an apposition, like ''Mary, a linguist''. This seems to be essentially (syntactically) an entity of type ''e'' that also wants to "write" a presupposition like "Mary is a linguist" to some environment. So, we say that it is an entity ''e'' in an effectful context ''W'', and we write this as the subtree having type ''W e''.
It turns out that we can extend this concept to syntax. For example, consider a [[noun phrase]] with an apposition, like ''Mary, a linguist''. This seems to be essentially (syntactically) an entity of type ''e'' that also wants to "write" a presupposition like "Mary is a linguist" to some environment. So, we say that it is an entity ''e'' in an effectful context ''<mark>W</mark>'', and we write this as the subtree having type ''<mark>W</mark> e''.


When we move up the tree to a bigger constituent like ''I saw Mary, a linguist'', we want to keep this effectful context and "lift" the rest of the sentence, ''I saw'' (of type ''e → t''), into it. We first turn ''e → t'' into ''W (e → t)'' and then compose this with our ''W e'' to get a ''W t''.
When we move up the tree to a bigger constituent like ''John saw Mary, a linguist'', we want to keep this effectful context and "lift" the rest of the sentence, ''John saw'' (of type ''e → t''), into it. We first turn ''e → t'' into ''<mark>W</mark> (e → t)'' and then compose this with our ''<mark>W</mark> e'' to get a ''<mark>W</mark> t''.
 
Similarly, a pronoun like ''her'' can be considered to be an entity ''e'' in an effectful "reader" context that provides a value for the binding: its type is ''<mark>R</mark> e''. This, again, might compose the same way to form a larger constituent like ''John saw her'', of type ''<mark>R</mark> t''.
 
When we compose the meaning of two effectful constituents, we have to pick a way to combine the contexts. For example, ''John saw Mary, a linguist'' might have type ''R (W t)'' or type ''W (R t)''. It depends on which effect we ''lift'' "into" the other effect before combining them.


Eventually, we arrive at a denoted sentence wrapped in a list of effects (presuppositions, bindings, focus…) gathered from everywhere in the sentence.
Eventually, we arrive at a denoted sentence wrapped in a list of effects (presuppositions, bindings, focus…) gathered from everywhere in the sentence.


(TODO: more examples from esslli slides, maybe in Toaq)
When parsing English, the freedom you have in deciding how to combine effects accounts for syntactic ambiguity. In an effectful version of [[Kuna]], we'd have a handful of rules saying exactly how effects combine, and this would answer questions about [[scope]].


== See also ==
== See also ==
* [https://simoncharlow.com/esslli/ Effectful composition in natural language semantics], slides by Dylan Bumford and Simon Charlow.
* [https://simoncharlow.com/esslli/ Effectful composition in natural language semantics], slides by Dylan Bumford and Simon Charlow.
* https://ncatlab.org/nlab/show/monad+%28in+linguistics%29
* https://ncatlab.org/nlab/show/monad+%28in+linguistics%29