我試圖實現使用Network.Linklater包一個基本slackbot:爲什麼強制實施Maybe monad?
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 4.0和Hackage 3.2之間的差距(日益擴大)我感到抱歉。我仍然試圖爲新的Web Socket API Slack提供一個足夠好的API,但也許我會盡快發佈它。 – hao
我在這裏上傳了4.0.0.0的新文檔:http://hlian.github.io/linklater/hackage/ – hao