繁体   English   中英

为什么一个Maybe monad被强制执行?

[英]Why is a Maybe monad enforced?

我正在尝试使用Network.Linklater包实现一个基本的slackbot:

https://github.com/hlian/linklater

该包定义了以下功能:

slashSimple :: (Command -> IO Text) -> Application
slashSimple f =
  slash (\command _ respond -> f command >>= (respond . responseOf status200))

我试图像这样消费:

kittensBot :: Command -> IO Text
kittensBot cmd = do
           putStrLn("+ Incoming command: " ++ show cmd)
           return "ok"

main :: IO ()
main = do
     putStrLn ("Listening on port: " ++ show port)
     run port (slashSimple kittensBot)
     where
       port = 3001

这会产生(在编译时):

Main.hs:20:28:
    Couldn't match type ‘Maybe Command’ with ‘Command’
    Expected type: Maybe Command -> IO Text
      Actual type: Command -> IO Text
    In the first argument of ‘slashSimple’, namely ‘kittensBot’
    In the second argument of ‘run’, namely ‘(slashSimple kittensBot)’

但是slashSimple的签名是(Command -> IO Text) -> Application kittensBot的签名不应该实现吗? 为什么不呢?

尽管GitHub master上的slashSimple的定义与你报告的一样,但是linklater-3.2.0.0中的Hackage版本是

slashSimple :: (Maybe Command -> IO Text) -> Application

如果你想在Hackage上使用这个包,你需要将kittensBot更新为:

kittensBot :: Maybe Command -> IO Text
kittensBot Nothing = ...
kittensBot (Just cmd) = do
       putStrLn("+ Incoming command: " ++ show cmd)
       return "ok"

或者,您可以从GitHub下载程序包并手动安装它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM