2017-04-13 52 views
0

試圖調用EffAff內:重複異常錯誤

import Prelude 
import Control.Monad.Aff (Aff, launchAff) 
import Control.Monad.Eff (Eff) 
import Control.Monad.Eff.Class (liftEff) 
import Control.Monad.Eff.Console (CONSOLE, log) 
import Control.Monad.Eff.Exception (EXCEPTION) 

f :: forall eff. Int -> Aff (exception :: EXCEPTION) String 
f i = pure $ show i 

g :: forall eff. Eff (console :: CONSOLE, exception :: EXCEPTION) Unit 
g = void $ launchAff do 
    s <- f 1 
    liftEff $ log s 

這讓我重複:

Could not match type 

    (exception :: EXCEPTION 
    , exception :: EXCEPTION 
    ) 

    with type 

    (console :: CONSOLE 
    , exception :: EXCEPTION 
    , exception :: EXCEPTION 
    ) 


while trying to match type Eff 
          (exception :: EXCEPTION 
          , exception :: EXCEPTION 
          ) 
    with type Eff 
       (console :: CONSOLE 
       , exception :: EXCEPTION 
      ) 
while checking that expression (apply void) (launchAff ((bind (...)) (\$0 -> 
                     ... 
                    ) 
                 ) 
              ) 
    has type Eff 
      (console :: CONSOLE 
      , exception :: EXCEPTION 
      ) 
      Unit 
in value declaration g 

我該怎麼辦?使用purescript版本0.11.3。

回答

0

這是因爲launchAff的類型,其輸入行中不包含exception標籤。一種解決方案是包括標籤兩次的g結果:

forall eff. Eff (console :: CONSOLE 
       , exception :: EXCEPTION 
       , exception :: EXCEPTION 
       ) Unit 

但是這意味着你需要使用catchException兩次外launchAff,這是不是很自然。

另一個是在launchAff的調用中使用catchException刪除標籤。

第三種方法是報告purescript-aff回購的錯誤,並嘗試更改launchAff的類型。