Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scotty post type wont allow effects

With:

mailHandler = do 
  name  <- param "name"
  email <- param "email"
  renderSendMail $ forwardMail name email

main = scotty 3000 $ post "/mail" mailHandler

I get the following type error:

    Couldn't match type `IO'
                  with `Web.Scotty.Internal.Types.ActionT T.Text IO'
    Expected type: Web.Scotty.Internal.Types.ActionT T.Text IO ()
      Actual type: IO ()
    In a stmt of a 'do' block: renderSendMail $ forwardMail name email
    In the expression:
      do { name <- param "name";
           email <- param "email";
           renderSendMail $ forwardMail name email }
    In an equation for `mailHandler':
        mailHandler
          = do { name <- param "name";
                 email <- param "email";
                 renderSendMail $ forwardMail name email }
Failed to install server-0.0.1
cabal: Error: some packages failed to install:
server-0.0.1 failed during the building phase. The exception was:
ExitFailure 1

After spending several hours, I still don't see how to resolve this. If I use a function internal to Scotty, no problem, but if I want to handling anything externally I get the error above. How can I get past this Web.Scotty.Internal.Types.ActionT T.Text IO ()

like image 506
Fresheyeball Avatar asked Dec 19 '22 11:12

Fresheyeball


1 Answers

Web.Scotty.Internal.Types.ActionT T.Text IO () is a monad transformer over IO. These usually implement the MonadIO class, so that you can use the liftIO function (from Control.Monad.IO.Class, if it hasn't been imported already) to "lift" IO actions into them:

liftIO . renderSendMail $ forwardMail name email
like image 113
Ørjan Johansen Avatar answered Dec 28 '22 09:12

Ørjan Johansen