我正在通过Luis Morillo 的 Haskell 初学者挑战 (snake-fury)学习 Haskell。\n练习 4中的任务之一是“实现Applicative新类型的实例”,其中新类型如下:
newtype GameStep m a = GameStep {runGameStep :: ReaderT BoardInfo (StateT GameState m) a}\nRun Code Online (Sandbox Code Playgroud)\n这是我的第一次尝试,但没有编译。
\ninstance (Applicative m) => Applicative (GameStep m) where\n pure a = GameStep $ pure a\n (GameStep r) <*> (GameStep s) = GameStep $ r <*> s\nRun Code Online (Sandbox Code Playgroud)\nGHC 说
\n \xe2\x80\xa2 Could not deduce (Monad m) arising from a use of \xe2\x80\x98pure\xe2\x80\x99\n from the context: Applicative m\n bound by …Run Code Online (Sandbox Code Playgroud) haskell ×1