(no commit message)
[lambda.git] / reader_monad_for_variable_binding.mdwn
index 2e24bab..ce4d087 100644 (file)
@@ -1,3 +1,5 @@
+[[!toc]]
+
 Substitution versus Environment-based Semantics
 -----------------------------------------------
 
 Substitution versus Environment-based Semantics
 -----------------------------------------------
 
@@ -146,7 +148,7 @@ Here we'll use a different monad. It's called the **Reader monad**. We define it
        (* we assume we've settled on some implementation of the environment *)
        type env = (char * int) list;;
 
        (* we assume we've settled on some implementation of the environment *)
        type env = (char * int) list;;
 
-       (* here's the type of our reader monad *)
+       (* here's the type of our Reader monad *)
        type 'a reader = env -> 'a;;
 
        (* here's our unit operation; it creates a reader-monad value that
        type 'a reader = env -> 'a;;
 
        (* here's our unit operation; it creates a reader-monad value that
@@ -155,7 +157,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 =
 
        (* 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 *)
        
 
        (* we also define two special-purpose operations on our reader-monad values *)
        
@@ -185,7 +190,7 @@ Now if we try:
        # let result = eval (Let('x',Constant 1,Addition(Variable 'x',Constant 2)));;
        - : int reader = <fun>
 
        # let result = eval (Let('x',Constant 1,Addition(Variable 'x',Constant 2)));;
        - : int reader = <fun>
 
-How do we see what integer that evaluates to? Well, it's an int-reader monad, which is a function from an `env` to an `int`, so we need to give it some `env` to operate on. We can give it the empty environment:
+How do we see what integer that evaluates to? Well, it's an int-Reader monad, which is a function from an `env` to an `int`, so we need to give it some `env` to operate on. We can give it the empty environment:
 
        # result [];;
        - : int = 3
 
        # result [];;
        - : int = 3
@@ -218,7 +223,7 @@ In Heim and Kratzer's textbook <cite>Semantics in Generative Grammar</cite>, the
 </pre></blockquote>
 
 
 </pre></blockquote>
 
 
-Now the normal way in which the nodes of such trees are related to each other is that the semantic value of a parent node is the result of applying the functional value of one of the daughter nodes to the value of the other daughter node. (The types determine which side is the function and which side is the argument.) One exception to this general rule is when multiple adjectives are joined together, as happens in \[[interprets complex English phrases]]. We'll ignore that though.
+Now the normal way in which the nodes of such trees are related to each other is that the semantic value of a parent node is the result of applying the functional value of one of the daughter nodes to the value of the other daughter node. (The types determine which side is the function and which side is the argument.) One exception to this general rule concerns intersective adjectives. (How does \[[complex]] combine with \[[phrases]]?) We'll ignore that though.
 
 Another exception is that Heim and Kratzer have to postulate a special rule to handle lambda abstraction. (This is their "Predicate Abstraction Rule.") Not only is it a special rule, but it's arguably not even a compositional rule. The basic idea is this. The semantic value of:
 
 
 Another exception is that Heim and Kratzer have to postulate a special rule to handle lambda abstraction. (This is their "Predicate Abstraction Rule.") Not only is it a special rule, but it's arguably not even a compositional rule. The basic idea is this. The semantic value of:
 
@@ -281,7 +286,7 @@ Substituting in the definition of `shift`, this is:
                = fun v -> (fun e -> S (lookup i ((i, v e) :: e)) Alice)
                = fun v -> (fun e -> S (v e) Alice)
 
                = fun v -> (fun e -> S (lookup i ((i, v e) :: e)) Alice)
                = fun v -> (fun e -> S (v e) Alice)
 
-In other words, it's a function from entity reader monads to a function from assignment functions to the result of applying S to the value of that entity reader-monad under that assignment function, and to Alice. Essentially the same as Heim and Kratzer's final value, except here we work with monadic values, such as functions from assignments to entities, rather than bare entities. And our derivation is completely compositional and uses the same composition rules for joining \[[who(i)]] to \[[Alice spurned i]] as it uses for joining \[[spurned]] to \[[i]] and \[[Alice]].
+In other words, it's a function from entity-Reader monads to a function from assignment functions to the result of applying S to the value of that entity reader-monad under that assignment function, and to Alice. Essentially the same as Heim and Kratzer's final value, except here we work with monadic values, such as functions from assignments to entities, rather than bare entities. And our derivation is completely compositional and uses the same composition rules for joining \[[who(i)]] to \[[Alice spurned i]] as it uses for joining \[[spurned]] to \[[i]] and \[[Alice]].
 
 What's not to like?
 
 
 What's not to like?