main'' :: Environment -> IO Solution
main'' env = loop (length $ servers env) Unknown
  where
    loop :: Int -> Solution -> IO Solution
    loop n previousSolution =
      case previousSolution of
        Solution _ -> check
        Unknown    -> check
        Unsatisfiable -> error "loop: unsat"
      where
        check :: IO Solution
        check = do
          newSolution <- solve (cnf env n)
          case newSolution of
            Unsatisfiable -> return previousSolution
            Solution _    -> loop (n-1) newSolution
            Unknown -> error "check: unknown"
main'' :: Environment -> IO Solution
main'' env = loop (length $ servers env) Unknown
  where
    loop :: Int -> Solution -> IO Solution
    loop n previousSolution =
      case previousSolution of
        Solution _ -> check
        Unknown    -> check
        Unsatisfiable -> error "loop: unsat"
      where
        check :: IO Solution
        check = do
          newSolution <- solve (cnf env n)
          case newSolution of
            Unsatisfiable -> return previousSolution
            Solution _    -> loop (n-1) newSolution
            Unknown -> error "check: unknown"
main'' env = loop (length $ servers env) Unknown
  where
    loop :: Int -> Solution -> IO Solution
    loop n previousSolution =
      case previousSolution of
        Solution _ -> check
        Unknown    -> check
        Unsatisfiable -> error "loop: unsat"
      where
        check :: IO Solution
        check = do
          newSolution <- solve (cnf env n)
          case newSolution of
            Unsatisfiable -> return previousSolution
            Solution _    -> loop (n-1) newSolution
            Unknown -> error "check: unknown"