I am trying to update (i.e., replace an element) of a list in a list comprehension, and then use the updated list for the next iteration of the list comprehension.
For example, in this code:
let n_nums = [replaceAt n (nums!!(n + 1)) nums | n <- [0..length nums]]
replaceAt
always works on nums
, whereas I would like it to work on n_nums
from the second iteration, and then on the newly updated list on the third iteration, and so on. What is a smart way to do that?