title: How to create a list in a recursive call where the first element needs to be handled differently?
body: <p>I am learning functional programming using Haskell. I am trying to create a function that takes a function f, and executes the function on some input x, n number of times.</p>
  <pre><code>repeat :: (a -&gt; a) -&gt; a -&gt; Int -&gt; [a]
  repeat f x n
  </code></pre>
  <p>So, the output list is like this:</p>
  <pre><code>[x, f(x), f(f(x)), ..., f^n(x)]
  </code></pre>
  <p>So far I have been able to come up with a function that I believe does this. It performs n times:</p>
  <pre><code>fn f a n = f a : fn f (f a) (n-1)
  </code></pre>
  <p>The problem I have now, is that I want the first element of the list to just be x. Right now, it is starting my list off at f(x). I tried playing around, but I'm not sure how to cover this &quot;base&quot; case in Haskell. Could someone lend a hand?</p>