I'm writing a function and it throws Prelude.head empty list
if I use the variable newBoard
where I have sortBoard
in the if-else it throws this error. If I use the original board
character it doesn't throw this error.
foo :: [[Char]] -> [(Int, Int)] -> [(Int, (Int, Int))] -> Int -> [(Int,Int)]-> [Int]-> [[Char]]
foo [] _ _ _ _ _ = []
foo board [] _ _ _ [] = board
foo board spot array number startArray move = nextStep
where
newBoard = set board (head spot) ('1')
tailSpot = tail spot
nextStep =
if tailSpot == []
then if (tail move) == []
then newBoard
else sortBoard newBoard array 1 [] (tail move)
else (foo newBoard tailSpot array 1 [] move)
For explination on this code, I have a game board and need to enter '1' in certain spots which are given by the variable spot
. If I have gone through all the spots(tailSpot
) and there are no more sections I need to change(move
) it should just return the new board. If I still have sections I need to change, I exit this function and go back to finding the spots in that section so I can come back and switch them. If I still have a section and spots left, I keep going through this function until all spots are changed.
Aucun commentaire:
Enregistrer un commentaire