I'm having a <<loop>> error for trying to redefine a value on an already defined index.
Simplified example:
ghci > let axs = array (1,5) [(1,1),(2,2),(3,3),(4,4),(5,5),(1, 1 + axs!1)]
ghci > axs
array (1,5) [(1,^CInterrupted.
This will loop. I'm assuming that the lazy nature of Data.Array is what is causing that behaviour.
This, on the other hand, won't loop and will work as expected (redefines index 1).
ghci > array (1,5) [(1,1),(2,2),(3,3),(4,4),(5,5),(1,6)]
array (1,5) [(1,6),(2,2),(3,3),(4,4),(5,5)]
Is there any way to redefine an indexed value with recursion to self? I'm assuming I need to force the evaluation of the wanted index to be able to "update" the value again using the previous one. Is that possible or I shouldn't/can't use the array this way?
array (1, 6) ...since you have 6 elements, not 5? The documentation says that this is indeed possible becausearrayis only strict in the index. It has to check each index to ensure that it's within the bounds and unique. You also have to have unique indices, so if you change it to(6, 1 + axs ! 1)then it'll work without problems.(1,1+axs!1)to(1,1 + axs!2)it will work. But I'm looking for a workaround to this self-referential behaviour (so it doesn't loop). As can be seen in the second example, indices in the list don't have to be unique, but it seems that recursion only works for indices which aren't equal to the current element (if recursion is defined). For example, even this will work:let axs = array (1,5) [(1,1),(2,2),(3,3),(4,4 + axs!5),(5,5),(1, 1 + axs!2)]