translating tweaks
[lambda.git] / hints / assignment_7_hint_4.mdwn
index 6b33b7a..046a45b 100644 (file)
                                                then let obj = List.nth h (r 'x') in q obj
                                                else false
                                        in (truth_value', r, h)
-               in bind_set u (fun one_dpm -> unit_set (bind_dpm one_dpm eliminator))
+               in set_bind u (fun one_dpm -> set_unit (dpm_bind one_dpm eliminator))
 
-       The first seven lines here just perfom the operation we described: return a `bool dpm` computation that only yields `true` when its input `(r, h)` associates variable `x` with the right sort of entity. The last line performs the `bind_set` operation. This works by taking each `dpm` in the set and returning a `unit_set` of a filtered `dpm`. The definition of `bind_set` takes care of collecting together all of the `unit_set`s that result for each different set element we started with.
+       The first seven lines here just perfom the operation we described: return a `bool dpm` computation that only yields `true` when its input `(r, h)` associates variable `x` with the right sort of entity. The last line performs the `set_bind` operation. This works by taking each `dpm` in the set and returning a `set_unit` of a filtered `dpm`. The definition of `set_bind` takes care of collecting together all of the `set_unit`s that result for each different set element we started with.
 
        We can call the `(fun one_dpm -> ...)` part \[[Qx]] and then updating `u` with \[[Qx]] will be:
 
-               bind_set u \[[Qx]]
+               set_bind u \[[Qx]]
 
        or as it's written using Haskell's infix notation for bind:
 
 
 *      Now what do we do with predicates? As before, we suppose we have a function `q` that maps entities to `bool`s. We want to turn it into a function that maps `entity dpm`s to `bool dpm`s. Eventually we'll need to operate not just on single `dpm`s but on sets of them, but first things first. We'll begin by lifting `q` into a function that takes `entity dpm`s as arguments and returns `bool dpm`s:
 
-               fun entity_dpm -> bind_dpm entity_dpm (fun e -> unit_dpm (q e))
+               fun entity_dpm -> dpm_bind entity_dpm (fun e -> dpm_unit (q e))
 
-       Now we have to transform this into a function that again takes single `entity dpm`s as arguments, but now returns a `bool dpm set`. This is easily done with `unit_set`:
+       Now we have to transform this into a function that again takes single `entity dpm`s as arguments, but now returns a `bool dpm set`. This is easily done with `set_unit`:
 
-               fun entity_dpm -> unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (q e)))
+               fun entity_dpm -> set_unit (dpm_bind entity_dpm (fun e -> dpm_unit (q e)))
 
        Finally, we realize that we're going to have a set of `bool dpm`s to start with, and we need to monadically bind \[[Qx]] to them. We don't want any of the monadic values in the set that wrap `false` to become `true`; instead, we want to apply a filter that checks whether values that formerly wrapped `true` should still continue to do so.
 
@@ -53,9 +53,9 @@
                        let eliminator : bool -> bool dpm =
                                fun truth_value ->
                                        if truth_value = false
-                                       then unit_dpm false
-                                       else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
-                       in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                                       then dpm_unit false
+                                       else dpm_bind entity_dpm (fun e -> dpm_unit (q e))
+                       in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
        Applied to an `entity_dpm`, that yields a function that we can bind to a `bool dpm set` and that will transform the doubly-wrapped `bool` into a new `bool dpm set`.
 
@@ -67,9 +67,9 @@
                in let entity_dpm = getx
                in let eliminator = fun truth_value ->
                        if truth_value = false
-                       then unit_dpm false
-                       else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       then dpm_unit false
+                       else dpm_bind entity_dpm (fun e -> dpm_unit (q e))
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
        <!--
        or, simplifying:
                        in (obj, r, h)
                in let eliminator = fun truth_value ->
                        if truth_value
-                       then bind_dpm getx (fun e -> unit_dpm (q e))
-                       else unit_dpm false
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       then dpm_bind getx (fun e -> dpm_unit (q e))
+                       else dpm_unit false
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
        -->
 
-       If we simplify and unpack the definition of `bind_dpm`, that's equivalent to:
+       If we simplify and unpack the definition of `dpm_bind`, that's equivalent to:
 
                let getx = fun (r, h) ->
                        let obj = List.nth h (r 'x')
                        if truth_value
                        then (fun (r, h) ->
                                        let (a, r', h') = getx (r, h)
-                                       in let u' = (fun e -> unit_dpm (q e)) a
+                                       in let u' = (fun e -> dpm_unit (q e)) a
                                        in u' (r', h')
-                       ) else unit_dpm false
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       ) else dpm_unit false
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
        which can be further simplified to:
 
                        then (fun (r, h) ->
                                        let obj = List.nth h (r 'x')
                                        let (a, r', h') = (obj, r, h)
-                                       in let u' = (fun e -> unit_dpm (q e)) a
+                                       in let u' = (fun e -> dpm_unit (q e)) a
                                        in u' (r', h')
-                       ) else unit_dpm false
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       ) else dpm_unit false
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
                let eliminator = fun truth_value ->
                        if truth_value
                        then (fun (r, h) ->
                                        let obj = List.nth h (r 'x')
-                                       in let u' = unit_dpm (q obj)
+                                       in let u' = dpm_unit (q obj)
                                        in u' (r, h)
-                       ) else unit_dpm false
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       ) else dpm_unit false
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
        -->
 
                let eliminator = fun truth_value ->
                        then (fun (r, h) ->
                                        let obj = List.nth h (r 'x')
                                        in (q obj, r, h)
-                       ) else unit_dpm false
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+                       ) else dpm_unit false
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
        This is a function that takes a `bool dpm` as input and returns a `bool dpm set` as output.
 
                                        then let obj = List.nth h (r 'x') in q obj
                                        else false
                                in (truth_value', r, h))
-               in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
+               in fun one_dpm -> set_unit (dpm_bind one_dpm eliminator)
 
        Can you persuade yourself that these are equivalent?)   
 
 *      Reviewing: now we've determined how to define \[[Q]] and \[[x]] such that \[[Qx]] can be the result of applying the function \[[Q]] to the `entity dpm` \[[x]]. And \[[Qx]] in turn is now a function that takes a `bool dpm` as input and returns a `bool dpm set` as output. We monadically bind this operaration to whatever `bool dpm set` we already have on hand:
 
-               bind_set u \[[Qx]]
+               set_bind u \[[Qx]]
 
        or: