3

The following code:

import Control.Monad.IO.Class

import Happstack.Server

test :: ServerPart String
test = liftIO (putStrLn "Test") >> ok "Test"

main = simpleHTTP nullConf test

is failing to compile with the message:

No instance for (MonadIO (ServerPartT IO))
  arising from a use of `liftIO'
Possible fix:
  add an instance declaration for (MonadIO (ServerPartT IO))
In the first argument of `(>>)', namely `liftIO (putStrLn "Test")'
In the expression: liftIO (putStrLn "Test") >> ok "Test"
In an equation for `test':
    test = liftIO (putStrLn "Test") >> ok "Test"

There appears to be a MonadIO instance here:

http://hackage.haskell.org/package/happstack-server-7.4.0/docs/Happstack-Server-Monads.html#t:ServerPartT

but adding a Happstack.Server.Monads import didn't change anything so I was hoping someone might be able to indicate what I'm doing wrong?

ryachza
  • 4,460
  • 18
  • 28
  • 1
    On a hunch, are `happstack-server` and your program using the same version of `transformers`? – Ørjan Johansen Jul 29 '15 at 04:34
  • @ØrjanJohansen I had that thought as well but I'm not sure how to check definitively? It looks like I have both 0.3.0.0 (from the Haskell Platform) and 0.4.2.0 (from Cabal) in ghc-pkg list but I don't know how to tell which is being used for what? – ryachza Jul 29 '15 at 10:52
  • @ØrjanJohansen I tried unregistering each version, and it looks like happstack is dependent on 0.3 and I would presume my program would try to use 0.4.2 since it's newer? Would you have any advice regarding resolving the issue? – ryachza Jul 29 '15 at 11:03
  • 2
    @ZJM You can use cabal sandbox, it ensures package versions consistency. BTW there is a feature request to improve the error: https://ghc.haskell.org/trac/ghc/ticket/9611 – Yuras Jul 29 '15 at 13:31
  • @Yuras Using a sandbox resolved it. Unfortunately it seems like I'll need to change my development workflow to make use of it, but I think long term it's for the best anyway. – ryachza Jul 29 '15 at 15:28

0 Answers0