我正在尝试使用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上使用该软件包,则需要将kitesBot更新为以下内容:
kittensBot :: Maybe Command -> IO Text
kittensBot Nothing = ...
kittensBot (Just cmd) = do
putStrLn("+ Incoming command: " ++ show cmd)
return "ok"
或者,您可以从GitHub下载该软件包并手动安装。