I have two things for the desired infinite list: its first element
x :: A
and function which generates the next element
f :: [A] -> A
What’s the best (most idiomatic? fastest?) way to create infinite list? I mean
xs = x : f [x] : f [x, f [x]] : f [x, f [x], f [x, f [x]]] : ...
The function you want can be implemented as:
The performance of
consrtuctInfdepends on the performance of it’s argument functionf. Assumingftakes O(N) time, thenconstructInfwill take O(M*N) time, where M is the number of elements from the result ofconstructInfthat you will inspect.