Haskell monad:无法匹配预期类型:(CError a,[String])与实际类型:a0 b0
Haskell monad: Couldn't match expected type: (Either CError a, [String]) with actual type: Either a0 b0
data CError = EA Int | EB String
deriving (Eq, Show)
type Env = [(VName, Value)]
newtype Test a = Test {runTest :: Env -> (Either CError a, [String]) }
我正在学习haskell,现在正在尝试定义一个 monad,但是遇到了这个错误,找不到解决方法。
我的代码如下:
instance Monad Test where
return a = Test $ \e -> (Right a, mempty)
m >>= f = Test $ \env -> case runTest m env of
(Right a, s) -> runTest (f a) env
(Left error) -> Left error
当前,“(Left error) -> Left error”这一行显示异常“Couldn't match expected type: (Either CError b, [String]) with actual type: Either a0 b1”。有人可以帮我弄这个吗?谢谢
(Either CError a, [String])
类型不包含 Left err
形式的任何值;你可能是说 (Left err, s)
.