My understanding is that this is the code you are executing:
import Database.MySQL.Base
insert_Producto = do
conn <- connect (defaultConnectInfo {ciUser = "root", ciPassword = "", ciDatabase = "prueba"})
oks <- executeMany conn "delete from producto" []
The compiler is complaining because you bind executeMany
to the variable oks
in the final line of a do
block. If you want your do block to return the output of executeMany
, you could do this:
insert_Producto1 = do
conn <- connect (defaultConnectInfo {ciUser = "root", ciPassword = "", ciDatabase = "prueba"})
executeMany conn "delete from producto" []
The reason why your code is problematic is that do
notation is desugared to a series of binds (>>=
). The code you wrote would be transformed to
insert_Producto2 = connect (defaultConnectInfo {ciUser = "root"
, ciPassword = ""
, ciDatabase = "prueba"})
>>= \conn ->
executeMany conn "delete from producto" []
>>= \oks ->
<???>
As you can see, there is no body in the last lambda function, which causes the error. The code block I proposed above would desugar to:
insert_Producto1 = connect (defaultConnectInfo {ciUser = "root"
, ciPassword = ""
, ciDatabase = "prueba"})
>>= \conn ->
executeMany conn "delete from producto" []
The last lambda now had a complete body.