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.
repeat :: (a -> a) -> a -> Int -> [a]
repeat f x n
So, the output list is like this:
[x, f(x), f(f(x)), ..., f^n(x)]
So far I have been able to come up with a function that I believe does this. It performs n times:
fn f a n = f a : fn f (f a) (n-1)
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 "base" case in Haskell. Could someone lend a hand?