[Haskell-beginners] Doubt in let expression

Lakshmi Narasimhan lakshminaras2002 at gmail.com
Sun Apr 11 03:12:07 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100411/c933af2a/attachment.html


More information about the Beginners mailing list