1
votes
handleStatements :: [Term] -> IO ()
handleStatements statements = do
    let (queries, clauses) = partition isQuery statements
    mapM_ (clausesEntailProof clauses) queries
    --apply clauses to queries and ignore result

handleArgs :: String-> IO ()
handleArgs args = do
    contents <- readFile $ args
    case parseInput contents of
      Left err -> print err
      Right statements -> handleStatements statements


main :: IO ()
main = do
  handleStatements(input)
    where input = getLine >>= (\str -> ((readIO str)::IO[Term])) 

I got error. Couldn't match expected type ‘[Term]’ with actual type ‘IO Term’. How can I fix this?

1
You can not use a where like this. - Willem Van Onsem
@WillemVanOnsem ...why not? Looks perfectly cromulent to me. Just misses a >>= in the body (as in input >>= handleStatements). - Daniel Wagner
@DanielWagner: Yes, but the question seems to indicate that where somehow performs the IO and then sets the result to input. You can indeed use input >>= handleStatements - Willem Van Onsem
@WillemVanOnsem Ah, I see. It seems "this" could refer to quite a lot of things when there's no antecedent. How confusing! Thanks for clarifying what you meant. - Daniel Wagner

1 Answers

3
votes

If you define input = … in the where clause, then input has type IO [Term], not [Term], so you can not pass input to the handleStatements.

You can write:

main :: IO ()
main = do
    input <- getLine >>= (\str -> ((readIO str)::IO[Term]))
    handleStatements input

But you are making things too complicated, you can work with readLn :: Read a => IO a instead:

main :: IO ()
main = do
    input <- readLn
    handleStatements input

or replace the do block with the (>>=) :: Monad m => m a -> (a -> m b) -> m b function:

main :: IO ()
main = readLn >>= handleStatements