2017-08-30 81 views
0

我正在嘗試attemptAff計算。請看下面的代碼:括號更改代碼執行

result <- 
    pool # withPool \connection -> do 
     execute_ ("insert into user (email, password) values ('" 
      <> unwrap userInfo.email <> "', '" <> unwrap userInfo.password <> "')") 
      connection 
    # attempt 

所得的attemptAff以後運行使用runAff

儘管使用了attempt,但將withPool中的錯誤傳播到了錯誤處理程序runAff

但是,如果括號內爲Aff添加周圍正在嘗試,錯誤是「捕獲」預期:

result <- 
    (pool # withPool \connection -> do 
     execute_ ("insert into user (email, password) values ('" 
      <> unwrap userInfo.email <> "', '" <> unwrap userInfo.password <> "')") 
      connection) 
    # attempt 

我是什麼在這裏失蹤,爲什麼是這兩個代碼的行爲代碼片斷有何不同?

回答

1

第一個代碼段相當於

result <- 
    pool # withPool (\connection -> do 
    execute_ ... 
    # attempt) 

和不

result <- 
    pool # (withPool \connection -> do 
      execute_ ...) 
     # attempt