2

The following do block throws the error "parse error on input `conn'" when I attempt to compile it. I have tried many different configurations of the if-then-else statement to no avail. The database logic worked before I added the conditional, so there isn't a problem with that. Do I have too many lines in the else? Is there any way to fix this without completely revamping the logic?

main = do
   contents <- BL.getContents
   let myData = decode contents :: Maybe Data
   if maybe True (\x -> result x /= "success") myData
      then error ("JSON download failed")
      else let myTrades = process myData
         conn <- connectSqlite3 "trades.db"
         insert <- DB.prepare conn "INSERT INTO trades VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"
         DB.executeMany insert $ map (\xs -> map DB.toSql xs) myTrades
         DB.commit conn
         DB.disconnect conn
1
  • There ended up being two problems with this. The first was the one described in the answer below; I needed "do" after "else". Additionally, the last four lines needed to be indented to be in the same column as the "l" in "let". Commented May 31, 2013 at 14:46

1 Answer 1

5

You need to introduce a do block after the else like so:

  else do let myTrades = process myData
          conn <- connectSqlite3 "trades.db"
          insert <- DB.prepare conn "INSERT INTO trades VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"
          DB.executeMany insert $ map (\xs -> map DB.toSql xs) myTrades
          DB.commit conn
          DB.disconnect conn
Sign up to request clarification or add additional context in comments.

1 Comment

I also needed to align the last four columns with the "l" in "let". This was the primary problem, though. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.