我正在尝试创建StateMonadPlus
一个MonadState
.
data StateMonadPlus s a = StateMonadPlus (s -> Either String (a, s))
instance MonadState s (StateMonadPlus s) where
-- get :: StateMonadPlus s
get = StateMonadPlus (\s -> Right (s, s))
-- put :: s -> StateMonadPlus ()
put s = StateMonadPlus (\_ -> Right ((), s))
代码编译得很好,但是当我取消注释 get 和 put 的类型时,它抱怨说
A3.hs:17:5: Misplaced type signature: get :: StateMonadPlus s
A3.hs:19:5: Misplaced type signature: put :: s -> StateMonadPlus ()
类型有什么问题?