title: How does the Reader monad's "ask" function work?
body: <pre><code>data T b = E | N b (T b) (T b) 
  
  
  f :: T b -&gt; Reader Int (T Int)
  f (N i l r) = ask &gt;&gt;= \x -&gt;  local ((-)4) (f l) &gt;&gt;= \l' -&gt; local ((-)1) (f r) &gt;&gt;= \r' -&gt; return (N x l' r')
  f E = return E
  </code></pre>
  
  <p>I have a problem with understanding how this code works. Especially, how does <code>ask</code> know where the environment is (in our case just <code>Int</code>)?</p>
  
  <p>To be more precise: I am an imperative programmer and in such languages it is easy. Methods can be called on any object like: <code>obj.f()</code>, or we have to pass data by argument when we want function use external data.</p>