1 (* This is the intensionality monad discussed in the lecture notes for week 7. *)
7 type 'a intension = s -> 'a;;
14 let bind m f (w:s) = f (m w) w;;
15 bind (unit 'a') unit 1;;
17 let left w x = match (w,x) with (2,'c') -> false | _ -> true;;
19 let extapp fn arg w = fn w (arg w);;
25 let saw w x y = (w < 2) && (y < x);;
26 extapp (extapp saw bill) ann 1;; (* true *)
27 extapp (extapp saw bill) ann 2;; (* false *)
29 let intapp fn arg w = fn w arg;;
31 let lift pred w arg = bind arg (fun x w -> pred w x) w;;
33 intapp (lift left) ann 1;; (* true: Ann still left in world 1 *)
34 intapp (lift left) cam 2;; (* false: Cam still didn't leave in world 2 *)
36 let lift2 pred w arg1 arg2 =
37 bind arg1 (fun x -> bind arg2 (fun y w -> pred w x y)) w;;
38 intapp (intapp (lift2 saw) bill) ann 1;; (* true: Ann saw Bill in world 1 *)
39 intapp (intapp (lift2 saw) bill) ann 2;; (* false: No one saw anyone in world 2 *)
41 let think (w:s) (p:s->t) (x:e) =
42 match (x, p 2) with ('a', false) -> false | _ -> p w;;
44 intapp (lift (intapp think
50 intapp (lift (intapp think
56 let swap f x y = f y x;;
57 bind cam (swap left) 2;; (* false *)