Doubt in let expression

Hello I am going through Walder's "Monads for Functional Programming" document. On page 9, there is a piece of code that provides the definition of return and bind for the State Monad I have pasted two variations of the code. The first one matches the definition given in the book. The second one is what I came up with. -- State Monad variation -- Retain the eval function as such -- Modify M , unit, * definitions type M a = State->(a, State) type State = Int unit :: a -> M a unit a = (\e->(a,e)) star :: M a -> (a -> M b) -> M b m `star` k = (\x -> let (a, aState) = m x in let (b, bState) = k a aState in (b, bState)) -- State Monad variation -- Retain the eval function as such -- Modify M , unit, * definitions type M a = State->(a, State) type State = Int unit :: a -> M a unit a = (\e->(a,e)) star :: M a -> (a -> M b) -> M b m `star` k = (\x -> let (a, aState) = m x (b, bState) = k a aState in (b, bState)) In the first definition of star, there are two let statements, while I found that one let statement would do the work anyway, as done in the second defintion of start I am not able to understand if there is any semantic implication in this syntatic variation of let. Please help. Thanks -- Regards Lakshmi Narasimhan T V

Hello There is no semantic implication of the difference. http://haskell.org/onlinereport/syntax-iso.html The Haskell syntax allows multiple declarations within a single let expression: exp10 -> ... | let decls in exp where decls is a list of declarations, (braces and colons can be replaced by layout): decls -> { decl1 ; ... ; decln } As a let ... in ... is an expression you can choose to write a list of declarations as nested let instead as you did in the second version.
From the original description of GHC intermediate form 'core' [1] page 3 shows that GHC chooses to desugar a let expression with a list of decls into nested singular let expressions, though this might have changed and also I might be misreading how GHC core distinguishes recursive let declarations which do appear as lists.
Best wishes Stephen [1] An External Representation for the GHC Core Language (DRAFT for GHC5.02) Andrew Tolmach and the GHC Team GHC doesn't define Haskell of course...

Thanks Stephen, that helps.
On Sun, Apr 11, 2010 at 1:58 PM, Stephen Tetley
Hello
There is no semantic implication of the difference.
http://haskell.org/onlinereport/syntax-iso.html
The Haskell syntax allows multiple declarations within a single let expression:
exp10 -> ... | let decls in exp
where decls is a list of declarations, (braces and colons can be replaced by layout):
decls -> { decl1 ; ... ; decln }
As a let ... in ... is an expression you can choose to write a list of declarations as nested let instead as you did in the second version.
From the original description of GHC intermediate form 'core' [1] page 3 shows that GHC chooses to desugar a let expression with a list of decls into nested singular let expressions, though this might have changed and also I might be misreading how GHC core distinguishes recursive let declarations which do appear as lists.
Best wishes
Stephen
[1] An External Representation for the GHC Core Language (DRAFT for GHC5.02) Andrew Tolmach and the GHC Team
GHC doesn't define Haskell of course... _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Regards Lakshmi Narasimhan T V
participants (2)
-
Lakshmi Narasimhan
-
Stephen Tetley