2

以下 do 块在我尝试编译时抛出错误“输入 `conn' 上的解析错误”。我尝试了许多不同的 if-then-else 语句配置,但均无济于事。数据库逻辑在我添加条件之前工作,所以没有问题。我在 else 中有太多行吗?有没有办法在不完全修改逻辑的情况下解决这个问题?

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
4

1 回答 1

5

您需要在likedo之后引入一个块:else

  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
于 2013-05-30T22:07:55.253 回答