61f48a71350a2ac6f97fd3bb2da46e9b479db0f8
[lambda.git] / hints / assignment_7_hint_3.mdwn
1
2 *       In def 2.5, they say the denotation of an e-type constant <code>&alpha;</code> wrt a discourse possibility `(r, g, w)` is whatever object the world `w` associates with <code>&alpha;</code>. Since we don't have worlds, this will just be an object.
3
4 *       They say the denotation of a predicate is whatever extension the world `w` associates with the predicate. Since we don't have worlds, this will just be an extension.
5
6 *       They say the denotation of a variable is the object which the store `g` assigns to the index that the assignment function `r` assigns to the variable. In other words, if the variable is `'x'`, its denotation wrt `(r, g, w)` is `g[r['x']]`.
7
8 We're going to keep all of that, except dropping the worlds. And instead of talking about
9
10 >       \[[expression]] in possibility `(r, g, w)`
11
12 we'll just talk about \[[expression]] and let that be a monadic object, implemented in part by a function that takes `(r, g)` as an argument.
13
14 More specifically, \[[expression]] will be a set of `'a discourse_possibility` monads, where `'a` is the appropriate type for *expression*, and the discourse possibility monads are themselves state monads where `(r, g)` is the state that gets updated. Those are implemented as functions from `(r, g)` to `(a, r', g')`, where `a` is a value of type `'a`, and `r', g'` are possibly altered assignment functions and stores.
15
16 *       In def 2.7, GS&V talk about an operation that takes an existing set of discourse possibilities, and extends each member in the set by allocating a new location in the store, and assigning a variable `'x'` to that location, which holds some object `d` from the domain. It will be useful to have a shorthand way of referring to this operation:
17
18                 let newpeg_and_bind (bound_variable : char) (d : entity) =
19                         fun ((r, g) : assignment * store) ->
20                                 let newindex = List.length g
21                                 (* first we store d at index newindex in g, which is at the very end *)
22                                 (* the following line achieves that in a simple but very inefficient way *)
23                                 in let g' = List.append g [d]
24                                 (* next we assign 'x' to location newindex *)
25                                 in let r' = fun v ->
26                                         if v = bound_variable then newindex else r v
27                                 (* the reason for returning a triple with () in first position will emerge *)
28                                 in ((), r',g')
29
30 *       At the top of p. 13 (this is in between defs 2.8 and 2.9), GS&V give two examples, one for \[[&exist;xPx]] and the other for \[[Qx]]. In fact it will be easiest for us to break \[[&exist;xPx]] into two pieces, \[[&exist;x]] and \[[Px]]. Let's consider expressions like \[[Px]]  first.
31
32         They say that the effect of updating an information state `s` with the meaning of "Qx" should be to eliminate possibilities in which the object associated with the peg associated with the variable `x` does not have the property Q. In other words, if we let `Q` be a function from objects to `bool`s, `s` updated with \[[Qx]] should be `s` filtered by the function `fun (r, g) -> let obj = List.nth g (r 'x') in Q obj`.
33
34         Recall that [we said before](/hints/assignment_7_hint_2) that `List.filter (test : 'a -> bool) (u : 'a set) : 'a set` is the same as:
35
36                 bind_set u (fun a -> if test a then unit_set a else empty_set)
37
38         Hence, updating `s` with \[[Qx]] should be:
39
40                 bind_set s (fun (r, g) -> if (let obj = List.nth g (r 'x') in Q obj) then unit_set (r, g) else empty_set)
41
42         We can call the `(fun (r, g) -> ...)` part \[[Qx]] and then updating `s` with \[[Qx]] will be:
43
44                 bind_set s [[Qx]]
45
46         or as it's written using Haskell's infix notation for bind:
47
48                 s >>= [[Qx]]
49
50 *       Now how shall we handle \[[&exist;x]]. As we said, GS&V really tell us how to interpret \[[&exist;xPx]], but what they say about this breaks naturally into two pieces, such that we can represent the update of `s` with \[[&exist;xPx]] as:
51
52                 s >>= [[&exist;x]] >>= [[Px]]
53
54
55
56