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