1
我試圖讓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))
代碼編譯就好了,但是當我取消對種獲取和說,它的抱怨
A3.hs:17:5: Misplaced type signature: get :: StateMonadPlus s
A3.hs:19:5: Misplaced type signature: put :: s -> StateMonadPlus()
有什麼問題的類型?