What I would like to do is define a function like this:
[f 0, f f 0, f f f 0, f f f f 0, f f f f f 0..]
Or in other words, where each element is the last element that is run through a function.
I have tried a few times to get this working with ways similar to ways I have seen the Fibonacci sequence in Haskell, by calling the list with the first few elements pre-defined:
fib = 0 : 1 : zipWith (+) fib (tail fib)
ls = 0 : f 0 : f (last ls)
If I define f as a simple addOne function like so:
f = (+ 1)
I get this error:
<interactive>:124:5: error:
* Occurs check: cannot construct the infinite type: a ~ [a]
Expected type: [[a]]
Actual type: [a]
* In the expression: 0 : (f 0) : f (last y)
In an equation for `y': y = 0 : (f 0) : f (last y)
* Relevant bindings include
y :: [[a]] (bound at <interactive>:124:1)
How do I create a list that functions like this does?