title: How to implement delete with foldr in Haskell
body: <p>I've been studying folds for the past few days. I can implement simple functions with them, like <code>length</code>, <code>concat</code> and <code>filter</code>. What I'm stuck at is trying to implement with <code>foldr</code> functions like <code>delete</code>, <code>take</code> and <code>find</code>. I have implemented these with explicit recursion but it doesn't seem obvious to me how to convert these types of functions to right folds.</p>
  
  <p>I have studied the tutorials by Graham Hutton and Bernie Pope. Imitating Hutton's <code>dropWhile</code>, I was able to implement <code>delete</code> with <code>foldr</code> but it fails on infinite lists.</p>
  
  <p>From reading <a href="https://stackoverflow.com/questions/20568276/implement-insert-in-haskell-with-foldr" title="Implement insert in haskell with foldr">Implement insert in haskell with foldr</a>, <a href="https://stackoverflow.com/questions/13057028/how-can-this-function-be-written-using-foldr" title="How can this function be written using foldr?">How can this function be written using foldr?</a> and <a href="https://stackoverflow.com/questions/15879940/implementing-take-using-foldr" title="Implementing take using foldr">Implementing take using foldr</a>, it would seem that I need to use <code>foldr</code> to generate a function which then does something. But I don't really understand these solutions and don't have an idea how to implement for example <code>delete</code> this way.</p>
  
  <p>Could you explain to me a general strategy for implementing with <code>foldr</code> lazy versions of functions like the ones I mentioned. Maybe you could also implement <code>delete</code> as an example since this probably is one of the easiest.</p>
  
  <p>I'm looking for a detailed explanation that a beginner can understand. I'm not interested in just solutions, I want to develop an understanding so I can come up with solutions to similar problems myself.</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit:</strong> At the moment of writing there is one useful answer but it's not quite what I was looking for. I'm more interested in an approach that uses foldr to generate a function, which then does something. The links in my question have examples of this. I don't quite understand those solutions so I would like to have more information on this approach.</p>