Okay, I'll try to give all the info needed here. This is one function of many functions we had to implement in my class in order to solve The Tower of Hanoi. The function in question takes in the 3 towers, in reverse order (biggest>smallest), the number of discs in my problem, and a string, which starts as empty, of the levels of the tower that have already been added to the list.
The function needs to recursively step through each level of the towers and print, in individual strings, what discs are in that level. Hopefully, that makes sense. I can elaborate more if need be.
Here's what I have so far:
stringFromBoardHelper :: Tower -> Tower -> Tower -> Int -> [String] -> [String]
stringFromBoardHelper _ _ _ _ [] = []
stringFromBoardHelper (t1:t1s) (t2:t2s) (t3:t3s) n discString = if n > 0
then stringFromBoardHelper t1s t2s t3s (n-1) ((stringFromThreeDiscs t1 t2 t3 n) : discString)
else discString
My problem is that right now my code just returns the empty list as my function starts with an empty list.
However, if I remove the empty listt case, then I get the error for not having exhaustive cases.Any Ideas?
[String]argument represents the work you've already done, then it being empty is not a very good base case! Your base case should be when there is no work left to do, not when all the work remains to be done. Your base case should probably be something meaning "all the pieces are in the place I wanted them already". - amalloy