Abraham P
Abraham P

Reputation: 15481

Why is a Maybe monad enforced?

I am attempting to implement a basic slackbot using the Network.Linklater package:

https://github.com/hlian/linklater

This package defines the following function:

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

I am attempting to consume this like so:

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

this produces (at compile time):

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)’

However the signature of slashSimple is (Command -> IO Text) -> Application. Shouldn't the signature of kittensBot fulfill that? Why doesn't it?

Upvotes: 2

Views: 142

Answers (1)

crockeea
crockeea

Reputation: 21811

Although the definition of slashSimple on GitHub master is as you reported, the Hackage version in linklater-3.2.0.0 is

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

If you want to use the package on Hackage, you'll need to update kittensBot to something like:

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

Alternatively, you can download the package from GitHub and manually install it.

Upvotes: 7

Related Questions