title: Haskell State Monad Coordinate
body: <p>I am trying to figure out how the state Monad works. I am trying to implement a function that gets two coordinates <code>(x, y)</code> and returns the <code>x</code> or <code>y</code> coordinate back. This should happen within the State Monad.</p>
  
  <pre><code>data Coordin = Coordin {x,y :: Float}
  </code></pre>
  
  <p>the functions that should be implemented they are looking like this: </p>
  
  <pre><code>getX :: State Coordin Float
  getY :: State Coordin Float
  </code></pre>
  
  <p>How can this work out?</p>
  
  <p>I have tried this:</p>
  
  <pre><code>newtype State s a = State { runState :: s -&gt; (a,s) }  
  
  getX:: State Coordin Float
  getX = State $ \(x, y) -&gt; (x, (x, y))
  </code></pre>
  
  <p>but getting this error message : </p>
  
  <pre><code>Couldn't match type ‘(Float, t0)’ with ‘Coordin’
      Expected type: State Coordin Float
        Actual type: State (Float, t0) Float
      In the expression: State $ \ (x, y) -&gt; (x, (x, y))
      In an equation for ‘getX’: getX = State $ \ (x, y) -&gt; (x, (x, y))
  </code></pre>