[Haskell-cafe] where versus let

Scott J. jscott at skynet.be
Fri May 6 11:17:38 EDT 2005


Hi,

Instead of the following piece of code :

data State s a = S(s -> (a,s))

instance Monad (State s) where
 return a      = S(\s -> (a,s))
 (S f ) >>= g  = S(\s -> let (a,s1)  = f s
                                       S fun   = g a
                                       (b,s2)  = fun s1
                                   in (b,s2) )

I thought to write it in the following form using "where":

data State s a = S(s -> (a,s))

instance Monad (State s) where
 return a      = S(\s -> (a,s))
 (S f ) >>= g  = S(\s -> (b,s2)
                                   where (a,s1)  = f s
                                             S fun   = g a
                                             (b,s2)  = fun s1  )

However the compiler does not accept this use of "where". What is the reason? 


Thanks
Jan                                    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20050506/ead8e4af/attachment.htm


More information about the Haskell-Cafe mailing list