X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=hints%2Fassignment_7_hint_5.mdwn;h=d44f824b05968d6de85e0cbc5b46ef97c77205b5;hb=6634e47c2d920a24c18277147590c8146b2d1284;hp=779fb2edc75b6b7e9085a9c6df5c22156c486ed6;hpb=ee78c002ea1d6c0ed2489ae5719c8f63e3ae1b3a;p=lambda.git diff --git a/hints/assignment_7_hint_5.mdwn b/hints/assignment_7_hint_5.mdwn index 779fb2ed..d44f824b 100644 --- a/hints/assignment_7_hint_5.mdwn +++ b/hints/assignment_7_hint_5.mdwn @@ -29,8 +29,8 @@ purely dealing with nondeterminism.
u updated with \[[∃x]] ≡
let extend one_dpm (d : entity) =
- bind_dpm one_dpm (new_peg_and_assign 'x' d)
- in bind_set u (fun one_dpm -> List.map (fun d -> extend one_dpm d) domain)
+ dpm_bind one_dpm (new_peg_and_assign 'x' d)
+ in set_bind u (fun one_dpm -> List.map (fun d -> extend one_dpm d) domain)
where `new_peg_and_assign` is the operation we defined in [hint 3](/hints/assignment_7_hint_3):
@@ -58,18 +58,18 @@ purely dealing with nondeterminism.
or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
- bind_set (bind_set u \[[∃x]]) \[[Px]]
+ set_bind (set_bind u \[[∃x]]) \[[Px]]
-* Let's compare this to what \[[∃xPx]] would look like on a non-dynamic semantics, for example, where we use a simple reader monad to implement variable binding. Reminding ourselves, we'd be working in a framework like this. (Here we implement environments or assignments as functions from variables to entities, instead of as lists of pairs of variables and entities. An assignment `r` here is what `fun c -> List.assoc c r` would have been in [week7](
+* Let's compare this to what \[[∃xPx]] would look like on a non-dynamic semantics, for example, where we use a simple Reader monad to implement variable binding. Reminding ourselves, we'd be working in a framework like this. (Here we implement environments or assignments as functions from variables to entities, instead of as lists of pairs of variables and entities. An assignment `r` here is what `fun c -> List.assoc c r` would have been in [week7](
/reader_monad_for_variable_binding).)
type assignment = char -> entity;;
type 'a reader = assignment -> 'a;;
- let unit_reader (value : 'a) : 'a reader = fun r -> value;;
+ let reader_unit (value : 'a) : 'a reader = fun r -> value;;
- let bind_reader (u : 'a reader) (f : 'a -> 'b reader) : 'b reader =
+ let reader_bind (u : 'a reader) (f : 'a -> 'b reader) : 'b reader =
fun r ->
let a = u r
in let u' = f a
@@ -89,7 +89,7 @@ purely dealing with nondeterminism.
fun entity_reader ->
fun r ->
let obj = entity_reader r
- in unit_reader (predicate obj)
+ in reader_unit (predicate obj)
The meaning of \[[Qx]] would then be:
@@ -98,7 +98,7 @@ purely dealing with nondeterminism.
\[[Qx]] ≡ \[[Q]] \[[x]] ≡
fun r ->
let obj = getx r
- in unit_reader (q obj)
+ in reader_unit (q obj)
Recall also how we defined \[[lambda x]], or as [we called it before](/reader_monad_for_variable_binding), \\[[who(x)]]:
@@ -115,7 +115,7 @@ purely dealing with nondeterminism.
fun (lifted_predicate : lifted_unary) ->
fun r -> exists (fun (obj : entity) ->
- lifted_predicate (unit_reader obj) r)
+ lifted_predicate (reader_unit obj) r)
That would be the meaning of \[[∃]], which we'd use like this:
@@ -136,7 +136,7 @@ purely dealing with nondeterminism.
in clause r'
in let lifted_exists =
fun lifted_predicate ->
- fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
+ fun r -> exists (fun obj -> lifted_predicate (reader_unit obj) r)
in fun bool_reader -> lifted_exists (shift 'x' bool_reader)
which we can simplify to:
@@ -149,7 +149,7 @@ purely dealing with nondeterminism.
in clause r'
in let lifted_exists =
fun lifted_predicate ->
- fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
+ fun r -> exists (fun obj -> lifted_predicate (reader_unit obj) r)
in fun bool_reader -> lifted_exists (shifted bool_reader)
fun bool_reader ->
@@ -158,11 +158,11 @@ purely dealing with nondeterminism.
let new_value = entity_reader r
in let r' = fun var -> if var = 'x' then new_value else r var
in bool_reader r'
- in fun r -> exists (fun obj -> shifted' (unit_reader obj) r)
+ in fun r -> exists (fun obj -> shifted' (reader_unit obj) r)
fun bool_reader ->
let shifted'' r obj =
- let new_value = (unit_reader obj) r
+ let new_value = (reader_unit obj) r
in let r' = fun var -> if var = 'x' then new_value else r var
in bool_reader r'
in fun r -> exists (fun obj -> shifted'' r obj)