let fst = fn x => x.1 in let snd = fn x => x.2 in let dots_pr = fun f(n) => if n = 0 then () else let _ = print (".") in f(n-1) in let row_pr = fn (n) => let _ = dots_pr (n-1) in let _ = print ("Q") in let _ = dots_pr (8-n) in print ("\n") in let board_pr = fn (bd) => let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in let bd = snd (bd) in let _ = row_pr (fst bd) in row_pr (snd (bd)) in let test2 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if x1 = x2 then false else if abs (x1 - x2) = 1 then false else true in let test_2 = fun f (xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else if x = y2 then false else if abs (x-y2) = n+2 then false else true in let test3 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_2 (x1, (x2, 0)) then test2 (x2) else false in let test_3 = fun f (xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else test_2 (x, (y2, n+1)) in let test4 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_3 (x1, (x2, 0)) then test3 (x2) else false in let test_4 = fun f (xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else test_3 (x, (y2, n+1)) in let test5 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_4 (x1, (x2, 0)) then test4 (x2) else false in let test_5 = fun f (xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else test_4 (x, (y2, n+1)) in let test6 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_5 (x1, (x2, 0)) then test5 (x2) else false in let test_6 = fun f (xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else test_5 (x, (y2, n+1)) in let test7 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_6 (x1, (x2, 0)) then test6 (x2) else false in let test_7 = fun f(xyn) => let x = fst(xyn) in let yn = snd (xyn) in let y = fst (yn) in let n = snd (yn) in let y1 = fst (y) in let y2 = snd (y) in if x = y1 then false else if abs(x-y1) = n+1 then false else test_6 (x, (y2, n+1)) in let test8 = fun f(x) => let x1 = fst(x) in let x2 = snd(x) in if test_7 (x1, (x2, 0)) then test7 (x2) else false in let incs = fun inc1(x) => if x < 8 then inc2 (0, x+1) else () and inc2(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test2 (x+1, y) then inc3 (0, (x+1, y)) else inc2 (x+1, y) else inc1 (y) and inc3(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test3 (x+1, y) then inc4 (0, (x+1, y)) else inc3 (x+1, y) else inc2 (y) and inc4(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test4 (x+1, y) then inc5 (0, (x+1, y)) else inc4 (x+1, y) else inc3 (y) and inc5(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test5 (x+1, y) then inc6 (0, (x+1, y)) else inc5 (x+1, y) else inc4 (y) and inc6(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test6 (x+1, y) then inc7 (0, (x+1, y)) else inc6 (x+1, y) else inc5 (y) and inc7(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test7 (x+1, y) then inc8 (0, (x+1, y)) else inc7 (x+1, y) else inc6 (y) and inc8(xy) => let x = fst (xy) in let y = snd (xy) in if (x < 8) then if test8 (x+1, y) then let _ = board_pr (x+1, y) in let _ = print ("\n") in inc8 (x+1, y) else inc8 (x+1, y) else inc7 (y) in incs#1 (0)