From 5555d992063202b118a612862085a06291bc6f47 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Wed, 3 Nov 2010 07:50:11 -0400 Subject: [PATCH] spell out reader-bind more explicitly Signed-off-by: Jim Pryor --- reader_monad_for_intensionality.mdwn | 4 +++- reader_monad_for_variable_binding.mdwn | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/reader_monad_for_intensionality.mdwn b/reader_monad_for_intensionality.mdwn index 55827340..7425be41 100644 --- a/reader_monad_for_intensionality.mdwn +++ b/reader_monad_for_intensionality.mdwn @@ -128,7 +128,9 @@ Now we are ready for the intensionality monad:
 type 'a intension = s -> 'a;;
 let unit x = fun (w:s) -> x;;
-let bind u f = fun (w:s) -> f (u w) w;;
+(* as before, bind can be written more compactly, but having
+   it spelled out like this will be useful down the road *)
+let bind u f = fun (w:s) -> let a = u w in let u' = f a in u' w;;
 
Then the individual concept `unit ann` is a rigid designator: a diff --git a/reader_monad_for_variable_binding.mdwn b/reader_monad_for_variable_binding.mdwn index 9ddddc88..3591c24b 100644 --- a/reader_monad_for_variable_binding.mdwn +++ b/reader_monad_for_variable_binding.mdwn @@ -155,7 +155,10 @@ Here we'll use a different monad. It's called the **Reader monad**. We define it (* here's our bind operation; how does it work? *) let bind (u : 'a reader) (f: 'a -> 'b reader) : 'b reader = - fun (e : env) -> f (u e) e + (* this can be written more compactly, but having it spelled out + like this will be useful down the road *) + fun (e : env) -> let a = u e in let u' = f a in u' e + (* we also define two special-purpose operations on our reader-monad values *) -- 2.11.0