title: Find the K'th element of a list using foldr
body: <p>I try to implement own safe search element by index in list. 
  I think, that my function have to have this signature:</p>
  
  <pre><code>safe_search :: [a] -&gt; Int -&gt; Maybe a
  safe_search xs n = foldr iteration init_val xs n
  iteration = undefined
  init_val = undefined
  </code></pre>
  
  <p>I have problem with implementation of iteration. I think, that it has to look like this:</p>
  
  <pre><code>safe_search :: [a] -&gt; Int -&gt; Maybe a
  safe_search xs n = foldr iteration init_val xs n
      where
      iteration :: a -&gt; (Int -&gt; [a]) -&gt; Int -&gt; a
      iteration x g 0 = []
      iteration x g n = x (n - 1)
      init_val :: Int -&gt; a
      init_val = const 0
  </code></pre>
  
  <p>But It has to many errors. My intuition about haskell is wrong.</p>