我正在尝试使用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
的签名不应该满足吗?为什么不呢?
答案 0 :(得分:7)
虽然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下载软件包并手动安装。