【发布时间】:2016-05-22 16:28:34
【问题描述】:
我刚刚开始学习 PureScript 效果,但我一直在尝试制作一个具有异常效果的函数。
lengthGt5 :: forall eff. String -> Eff (err :: EXCEPTION | eff) String
lengthGt5 a = if (length a <= 5)
then throwException $ error "Word is not the right length!"
else a
main = do
word <- catchException handleShortWord (lengthGt5 "test")
log word
where
handleShortWord err = do
log (message err)
return "Defaut::casserole"
当我尝试运行它时,我收到以下错误
无法匹配类型
String
with type
Eff
( err :: EXCEPTION
| eff0
)
String
我知道 lengthGt5 在非异常情况下需要返回一个包裹在 Eff 中的字符串,但我不确定如何围绕值 a 创建一个“空效果包装器”。我考虑的对吗?
【问题讨论】:
-
请注意,
pure现在用return代替 github.com/purescript/purescript/wiki/…
标签: exception-handling effects purescript