title: Where with lambda in haskell
body: <p>I am reading the 2nd edition of the (great) book from Graham Hutton <a href="http://www.cs.nott.ac.uk/~pszgmh/pih.html" rel="nofollow noreferrer">"Progamming in Haskell"</a> (Cambridge Press). </p>
  
  <p>Reading the State Monad section, I stumbled on a small task that I gave myself.</p>
  
  <p>How could you rewrite the following using <code>where</code> instead of <code>let</code>?</p>
  
  <pre><code>type State = Int
  newtype ST a = S (State -&gt; (a, State))
  
  instance Functor ST where
      -- fmap :: (a -&gt; b) -&gt; ST a  -&gt; ST b
      fmap g st = S (\state -&gt; let (x, s') = app st state in (g x, s'))
  </code></pre>
  
  <p>I tried variations around this code but it doesn't work:</p>
  
  <pre><code>instance Functor ST where
     -- fmap :: (a -&gt; b) -&gt; ST a  -&gt; ST b
     fmap g st = S (\state -&gt; (g x, newstate))
                where (x, newstate) = app st state
  </code></pre>
  
  <p>I know it's not useful per se, but I would like to know if and how it is possible.</p>