【发布时间】:2015-04-26 01:40:25
【问题描述】:
我打字有问题。我开始使用this article 研究 Monad 变压器。然后我几乎没有改变他们的例子。现在,我的代码是:
data PwdError = PwdError String
type PwdErrorMonad = ErrorT PwdError IO
isValid :: String -> ErrorT String PwdErrorMonad Bool
isValid s
| length s < 5 = throwError "password is short!"
| otherwise = return True
现在,我有错误:
No instance for (Error PwdError) arising from a use of `throwError'
In the expression: throwError "password is short!"
In an equation for `isValid':
isValid s
| length s < 5 = throwError "password is too short!"
| otherwise = return True
你能帮我编译一下这个程序吗?
【问题讨论】:
-
您需要在代码中的某处添加
instance Error PwdError where ...。查看Error类的文档,了解您需要实现哪些功能。
标签: haskell types monads monad-transformers