catchException 不会消除效果
catchException doesn't remove the effect
在下面的模块中,函数 g 编译时没有任何注释,但函数 f 给出了消息 "Could not match type",并解释说 (err :: Exception | e) does not match ().
但是,throwException 和 toISOString return Eff 中的值具有 EXCEPTION 效果(可能还有其他效果)。
看起来好像catchException没有去除f中的EXCEPTION效果,但是确实去除了g中的效果。实际上,f 的推断类型是:
f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
这是为什么?
module Problem.With.Exception where
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (catchException, throwException, error)
import Data.DateTime (DateTime(..))
import Data.JSDate (fromDateTime, toISOString)
import Prelude (pure, ($), (<>), show, discard, bind)
g :: DateTime -> Eff () String
g d = catchException
(\_ -> pure "Some message")
(throwException $ error "Bla")
-- This is the inferred type for f:
-- f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
-- But this is the type I hope for:
f :: DateTime -> Eff () String
f d = catchException
(\_ -> pure "Some message")
(toISOString (fromDateTime d))
我在干净的环境下试了一下,模块按原样编译(符合预期的类型,没有EXCEPTION
效果)。
我认为您可能有一些 library/code 版本问题。
也许你想做
rm -rf node_modules
rm -rf bower_components
npm install
bower install
pulp build
我在 package.json
中有以下库版本:
"devDependencies": {
"bower": "^1.8.2",
"pulp": "^12.0.1",
"purescript": "^0.11.7"
}
bower.json
中的这些:
"dependencies": {
"purescript-prelude": "^3.1.1",
"purescript-console": "^3.0.0",
"purescript-exceptions": "^3.1.0",
"purescript-js-date": "^5.1.0",
"purescript-datetime": "^3.4.1"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0"
}
在下面的模块中,函数 g 编译时没有任何注释,但函数 f 给出了消息 "Could not match type",并解释说 (err :: Exception | e) does not match ().
但是,throwException 和 toISOString return Eff 中的值具有 EXCEPTION 效果(可能还有其他效果)。
看起来好像catchException没有去除f中的EXCEPTION效果,但是确实去除了g中的效果。实际上,f 的推断类型是:
f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
这是为什么?
module Problem.With.Exception where
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (catchException, throwException, error)
import Data.DateTime (DateTime(..))
import Data.JSDate (fromDateTime, toISOString)
import Prelude (pure, ($), (<>), show, discard, bind)
g :: DateTime -> Eff () String
g d = catchException
(\_ -> pure "Some message")
(throwException $ error "Bla")
-- This is the inferred type for f:
-- f :: forall e. DateTime -> Eff (err :: EXCEPTION | e) String
-- But this is the type I hope for:
f :: DateTime -> Eff () String
f d = catchException
(\_ -> pure "Some message")
(toISOString (fromDateTime d))
我在干净的环境下试了一下,模块按原样编译(符合预期的类型,没有EXCEPTION
效果)。
我认为您可能有一些 library/code 版本问题。
也许你想做
rm -rf node_modules
rm -rf bower_components
npm install
bower install
pulp build
我在 package.json
中有以下库版本:
"devDependencies": {
"bower": "^1.8.2",
"pulp": "^12.0.1",
"purescript": "^0.11.7"
}
bower.json
中的这些:
"dependencies": {
"purescript-prelude": "^3.1.1",
"purescript-console": "^3.0.0",
"purescript-exceptions": "^3.1.0",
"purescript-js-date": "^5.1.0",
"purescript-datetime": "^3.4.1"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0"
}