X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=hints%2Fassignment_7_hint_4.mdwn;h=ae17ce1d551ee945796adb589e9b76f9185dcc44;hp=71ed621b6b108a5129242340d9f2723d5610dcad;hb=c0d0fef36aacfcb9e66c43b39281491f44757850;hpb=1ad04632ef842a0591d1387d7709afc82f6ed3bd diff --git a/hints/assignment_7_hint_4.mdwn b/hints/assignment_7_hint_4.mdwn index 71ed621b..ae17ce1d 100644 --- a/hints/assignment_7_hint_4.mdwn +++ b/hints/assignment_7_hint_4.mdwn @@ -46,13 +46,14 @@ Finally, we realize that we're going to have a set of `bool dpm`s to start with, and we need to compose \[[Qx]] with 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. - This is most easily done like this: + This could be handled like this: fun entity_dpm -> - fun truth_value -> + let eliminate_non_Qxs = fun truth_value -> if truth_value = false then empty_set - else unit_set (bind dpm entity_dpm (fun e -> unit_dpm (Q e))) + else unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (Q e))) + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) 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`. @@ -64,27 +65,29 @@ let obj = List.nth h (r 'x') in (obj, r, h) in let entity_dpm = getx - in fun truth_value -> + in let eliminate_non_Qxs = fun truth_value -> if truth_value = false then empty_set else unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (Q e))) + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) or, simplifying: let getx = fun (r, h) -> let obj = List.nth h (r 'x') in (obj, r, h) - in fun truth_value -> + in let eliminate_non_Qxs = fun truth_value -> if truth_value then unit_set (bind_dpm getx (fun e -> unit_dpm (Q e))) else empty_set + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) unpacking the definition of `bind_dpm`, that is: let getx = fun (r, h) -> let obj = List.nth h (r 'x') in (obj, r, h) - in fun truth_value -> + in let eliminate_non_Qxs = fun truth_value -> if truth_value then unit_set ( fun (r, h) -> @@ -92,10 +95,11 @@ in let u' = (fun e -> unit_dpm (Q e)) a in u' (r', h') ) else empty_set - + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) + which is: - in fun truth_value -> + let eliminate_non_Qxs = fun truth_value -> if truth_value then unit_set ( fun (r, h) -> @@ -104,18 +108,22 @@ in let u' = (fun e -> unit_dpm (Q e)) a in u' (r', h') ) else empty_set - + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) + which is: - in fun truth_value -> + let eliminate_non_Qxs = fun truth_value -> if truth_value then unit_set ( fun (r, h) -> let obj = List.nth h (r 'x') in let u' = unit_dpm (Q obj) - in u' (r', h') + in u' (r, h) ) else empty_set - + in fun one_dpm -> (bind_dpm one_dpm eliminate_non_Qxs) + + This is a function that takes a `bool dpm` as input and returns a `bool dpm set` as output. + This is a bit different than the \[[Qx]] we had before: let eliminate_non_Qxs = (fun truth_value -> @@ -125,9 +133,9 @@ 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 eliminate_non_Qxs)) + in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs) - because that one passed through every `bool dpm` that wrapped a `false`; whereas now we're discarding some of them. But these will work equally well. We can implement either behavior (or, as we said before, the behavior of never passing through a wrapped `false`). + because that one passed through every `bool dpm` that wrapped a `false`; whereas now we're discarding some of them. But these will work equally well. We can implement either behavior (or, as we said before, the behavior of never returning any wrapped `false`s). * 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 compose this with a `bool dpm set` we already have on hand: