Alright so I am attempting to create a Sudoku Solver in Haskell but I'm getting an error saying that I couldn't match the expected type [[Int]] with the actual type IO (). Here is my attempt at the recursive solver, the error message, and other relevant pieces of code:
Recursive Solver Attempt:
test i j q s_board = if ((valid_row i q s_board )&&(valid_column j q s_board)&& (valid_sub_board i j q s_board)) then (solve (set_value i j q s_board)) else s_board
foo i j s_board = if ((get_value i j s_board) == 0) then [test i j q s_board | q <- [1..9]] else s_board
solve s_board = if (full_board s_board) then (print_board s_board) else [foo i j s_board | i <- [0..8], j <- [0..8]]
This question would be extremely long if I included all the definitions for the valid column, row, etc. functions, but I've checked to make sure those work. With this code I'm getting the following error message:
Couldn't match expected type `[[Int]]' with actual type `IO ()'
In the return type of a call of `print_board'
In the expression: (print_board s_board)
In the expression:
if (full_board s_board) then
(print_board s_board)
else
[foo i j s_board | i <- [0 .. 8], j <- [0 .. 8]]
Also here is the code that I'm using to print my board:
-- showLine: this function provides formating for a single row
showLine :: [Int] -> String
showLine = intercalate " | "
. map unwords
. chunksOf 3
. map show
-- showBoad: this function provides formating for the entire board
showBoard :: [[Int]] -> String
showBoard = intercalate "---------------------\n"
. map unlines
. chunksOf 3
. map showLine
-- print_board: this function is meant to print out the entire board
print_board :: [[Int]] -> IO ()
print_board s_board = putStrLn $ showBoard s_board
Do you guys see what's the problem with what I have so far. I'm totally new to Haskell and this is the first real program that I've attempted. Any help would be greatly appreciated.