我有点被这个错误信息难住了
Warning: Error in module Chapter2:
Error in value declaration unionIsForeign:
Error checking that type
Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace | u8717) u8715
subsumes type
Data.Either.Either Data.Foreign.ForeignError Chapter2.Union
Error at src/Chapter2.purs line 16, column 18 - line 20, column 1:
Cannot unify type
Control.Monad.Eff.Eff
with type
Data.Either.Either
这是这段代码的结果
module Chapter2 where
import Debug.Trace
import Data.Foreign
import Data.Foreign.Class
import Control.Monad.Eff
sideeffect :: forall e. Number -> Eff (trace :: Trace | e) Number
sideeffect v = return v
data Union = S String
instance unionIsForeign :: IsForeign Union where
read value = do
v <- sideeffect 42
return $ S "Test"
main = do
trace "Test"
为什么需要统一Eff
和Either
?这似乎只在实例化 IsForeign 类型类时出现。
sideeffect
运行愉快main
- 当然 main 有一个签名,说明它使用 Eff Monad
> :t Chapter2.main
Compiling Chapter2
forall t20. Control.Monad.Eff.Eff (trace :: Debug.Trace.Trace | t20) Prelude.Unit