6887487fa69298fad8b85ba96ed741e69fcfec8a
[lambda.git] / intensionality_monad.mdwn
1 The intensionality monad
2 ------------------------
3
4 In the meantime, we'll look at several linguistic applications for
5 monads, based on what's called the *reader monad*, starting with
6 intensional function application.  
7
8 First, the familiar linguistic problem:
9
10            Bill left.  
11            Cam left.
12            Ann believes [Bill left].
13            Ann believes [Cam left].
14
15 We want an analysis on which all four of these sentences can be true
16 simultaneously.  If sentences denoted simple truth values or booleans,
17 we have a problem: if the sentences *Bill left* and *Cam left* are
18 both true, they denote the same object, and Ann's beliefs can't
19 distinguish between them.
20
21 In Shan (2001) [Monads for natural language
22 semantics](http://arxiv.org/abs/cs/0205026v1), Ken shows that making
23 expressions sensitive to the world of evaluation is conceptually the
24 same thing as making use of a *reader monad*.  This technique was
25 beautifully re-invented by Ben-Avi and Winter (2007) in their paper [A
26 modular approach to
27 intensionality](http://parles.upf.es/glif/pub/sub11/individual/bena_wint.pdf),
28 though without explicitly using monads.
29
30 All of the code in the discussion below can be found here: [[intensionality-monad.ml]].
31 To run it, download the file, start OCaml, and say 
32
33         # #use "intensionality-monad.ml";;
34
35 Note the extra `#` attached to the directive `use`.
36
37 The traditional solution to the problem sketched above is to allow
38 sentences to denote a function from worlds to truth values, what
39 Montague called an intension.  So if `s` is the type of possible
40 worlds, we have the following situation:
41
42
43 <pre>
44 Extensional types              Intensional types       Examples
45 -------------------------------------------------------------------
46
47 S         t                    s->t                    John left
48 DP        e                    s->e                    John
49 VP        e->t                 (s->e)->s->t            left
50 Vt        e->e->t              (s->e)->(s->e)->s->t    saw
51 Vs        t->e->t              (s->t)->(s->e)->s->t    thought
52 </pre>
53
54 This system is modeled on the way Montague arranged his grammar.
55 There are significant simplifications: for instance, determiner
56 phrases are thought of as corresponding to individuals rather than to
57 generalized quantifiers.  
58
59 The main difference between the intensional types and the extensional
60 types is that in the intensional types, the arguments are functions
61 from worlds to extensions: intransitive verb phrases like "left" now
62 take intensional concepts as arguments (type s->e) rather than plain
63 individuals (type e), and attitude verbs like "think" now take
64 propositions (type s->t) rather than truth values (type t).
65 In addition, the result of each predicate is an intension.
66 This expresses the fact that the set of people who left in one world
67 may be different than the set of people who left in a different world.
68 Normally, the dependence of the extension of a predicate to the world
69 of evaluation is hidden inside of an evaluation coordinate, or built
70 into the the lexical meaning function, but we've made it explicit here
71 in the way that the intensionality monad makes most natural.
72
73 The intenstional types are more complicated than the intensional
74 types.  Wouldn't it be nice to make the complicated types available
75 for those expressions like attitude verbs that need to worry about
76 intensions, and keep the rest of the grammar as extensional as
77 possible?  This desire is parallel to our earlier desire to limit the
78 concern about division by zero to the division function, and let the
79 other functions, like addition or multiplication, ignore
80 division-by-zero problems as much as possible.
81
82 So here's what we do:
83
84 In OCaml, we'll use integers to model possible worlds:
85
86         type s = int;;
87         type e = char;;
88         type t = bool;;
89
90 Characters (characters in the computational sense, i.e., letters like
91 `'a'` and `'b'`, not Kaplanian characters) will model individuals, and
92 OCaml booleans will serve for truth values.
93
94 <pre>
95 let ann = 'a';;
96 let bill = 'b';;
97 let cam = 'c';;
98
99 let left1 (x:e) = true;; 
100 let saw1 (x:e) (y:e) = y < x;; 
101
102 left1 ann;;
103 saw1 bill ann;; (* true *)
104 saw1 ann bill;; (* false *)
105 </pre>
106
107 So here's our extensional system: everyone left, including Ann;
108 and Ann saw Bill, but Bill didn't see Ann.  (Note that Ocaml word
109 order is VOS, verb-object-subject.)
110
111 Now we add intensions.  Because different people leave in different
112 worlds, the meaning of *leave* must depend on the world in which it is
113 being evaluated:
114
115     let left (x:e) (w:s) = match (x, w) with ('c', 2) -> false | _ -> true;;
116
117 This new definition says that everyone always left, except that 
118 in world 2, Cam didn't leave.
119
120     let saw x y w = (w < 2) && (y < x);;
121     saw bill ann 1;; (* true: Ann saw Bill in world 1 *)
122     saw bill ann 2;; (* false: no one saw anyone in world 2 *)
123
124 Along similar lines, this general version of *see* coincides with the
125 `saw1` function we defined above for world 1; in world 2, no one saw anyone.
126
127 Just to keep things straight, let's get the facts of the world set:
128
129 <pre>
130      World 1: Everyone left.
131               Ann saw Bill, Ann saw Cam, Bill saw Cam, no one else saw anyone.              
132      World 2: Ann left, Bill left, Cam didn't leave.
133               No one saw anyone.
134 </pre>
135
136 Now we are ready for the intensionality monad:
137
138 <pre>
139 type 'a intension = s -> 'a;;
140 let unit x (w:s) = x;;
141 let bind m f (w:s) = f (m w) w;;
142 </pre>
143
144 Then the individual concept `unit ann` is a rigid designator: a
145 constant function from worlds to individuals that returns `'a'` no
146 matter which world is used as an argument.  This is a typical kind of
147 thing for a monad unit to do.
148
149 Then combining a prediction like *left* which is extensional in its
150 subject argument with a monadic subject like `unit ann` is simply bind
151 in action:
152
153     bind (unit ann) left 1;; (* true: Ann left in world 1 *)
154     bind (unit cam) left 2;; (* false: Cam didn't leave in world 2 *)
155
156 As usual, bind takes a monad box containing Ann, extracts Ann, and
157 feeds her to the extensional *left*.  In linguistic terms, we take the
158 individual concept `unit ann`, apply it to the world of evaluation in
159 order to get hold of an individual (`'a'`), then feed that individual
160 to the extensional predicate *left*.
161
162 We can arrange for an extensional transitive verb to take intensional
163 arguments:
164
165     let lift f u v = bind u (fun x -> bind v (fun y -> f x y));;
166
167 This is the exact same lift predicate we defined in order to allow
168 addition in our division monad example.
169
170 <pre>
171 lift saw (unit bill) (unit ann) 1;;  (* true *)
172 lift saw (unit bill) (unit ann) 2;;  (* false *)
173 </pre>
174
175 Ann did see bill in world 1, but Ann didn't see Bill in world 2.
176
177 Finally, we can define our intensional verb *thinks*.  *Think* is
178 intensional with respect to its sentential complement, but extensional
179 with respect to its subject.  (As Montague noticed, almost all verbs
180 in English are extensional with respect to their subject; a possible
181 exception is "appear".)
182
183     let thinks (p:s->t) (x:e) (w:s) = 
184       match (x, p 2) with ('a', false) -> false | _ -> p w;;
185
186 Ann disbelieves any proposition that is false in world 2.  Apparently,
187 she firmly believes we're in world 2.  Everyone else believes a
188 proposition iff that proposition is true in the world of evaluation.
189
190     bind (unit ann) (thinks (bind (unit bill) left)) 1;;
191
192 So in world 1, Ann thinks that Bill left (because in world 2, Bill did leave).
193
194     bind (unit ann) (thinks (bind (unit cam) left)) 1;;
195
196 But even in world 1, Ann doesn't believe that Cam left (even though he
197 did: `bind (unit cam) left 1 == true`).  Ann's thoughts are hung up on
198 what is happening in world 2, where Cam doesn't leave.
199
200 *Small project*: add intersective ("red") and non-intersective
201  adjectives ("good") to the fragment.  The intersective adjectives
202  will be extensional with respect to the nominal they combine with
203  (using bind), and the non-intersective adjectives will take
204  intensional arguments.