How to read and process multiple lines in Idris?

What happens

I’m having trouble figuring out how to read and process multiple lines from stdin.

What do you understand or find about that problem

I need to do a while-ish “loop” to process the test cases for a Codeabbey challenge, the test data is presented as the number of cases followed by the data for each case separated by a newline.

You make any workaround? What did you do?

I tried moving the code to a method I can recursively call, but I’m gettting a not very specific (at least to me!) syntax error. I am aware there are implementations of this in other .idr files of the repo, but I do not understand them enough to properly adapt them and I’m sure such ‘borrowing’ would not comply with the Immersion rules anyway.

Evidences

Line 40 provides the number of test cases while lines 41 to 44 will solve one case
image
This is my attempt to do it recursively and call this method from Main
image
But the compiler throws this error on line 21:

I need help with

I know the code is very rough around the edges, some lines could be moved around, but I just need a hint of helpful tip about how to recursively handle these cases, it has been very difficult to find documentation on this so far.

You are losing avgArr variable, if you see the function calcAvg doesn’t recover the current state of the avgArr

also, you need have into account caclAvg function is using an IO function (getLine), probably you have to express that in the function definition