title: Haskell help to understand this State monad code: where is runState defined?
body: <p>I am new to Haskell and trying to understand monads. I am going thru <a href="https://github.com/sdiehl/wiwinwlh/blob/master/src/02-monads/state_impl.hs">this code</a>
  Putting it here for quick reference </p>
  
  <pre><code>newtype State s a = State { runState :: s -&gt; (a,s) }
  
  instance Monad (State s) where
    return a = State $ \s -&gt; (a, s)
  
    State act &gt;&gt;= k = State $ \s -&gt;
      let (a, s') = act s
      in runState (k a) s'
  
  get :: State s s
  get = State $ \s -&gt; (s, s)
  
  put :: s -&gt; State s ()
  put s = State $ \_ -&gt; ((), s)
  
  modify :: (s -&gt; s) -&gt; State s ()
  modify f = get &gt;&gt;= \x -&gt; put (f x)
  
  evalState :: State s a -&gt; s -&gt; a
  evalState act = fst . runState act
  
  execState :: State s a -&gt; s -&gt; s
  execState act = snd . runState act
  </code></pre>
  
  <p>I didn't get where the function <code>runState</code> is defined. It seems its type is declared in <code>newtype State s a = State { runState :: s -&gt; (a,s) }</code>.
  The most puzzling part is this code compiles without any error.</p>
  
  <p>Where is <code>runState</code> defined? where is its code?</p>