I'm trying to extract a basic post request using code from this question (except that I'm using lbsBackEnd instead of the no-longer-existing lbsSink).
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai.Handler.Warp (run)
import qualified Data.ByteString.Char8 as C
import Network.Wai.Parse (parseRequestBody, lbsBackEnd)
import Network.Wai(Response(..))
import Network.HTTP.Types(status200)
import Blaze.ByteString.Builder
main = run 3000 app
app req = do
(params, _) <- parseRequestBody lbsBackEnd req
let r = C.concat $ map (\(x,y) -> C.concat [x,y]) params
return $ ResponseBuilder
status200
[("Content-Type", "text/plain")]
$ fromByteString r
Comments in that question suggest that this should work, but I'm getting the type error
Couldn't match expected type `C.ByteString'
with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
Expected type: [(C.ByteString, C.ByteString)]
Actual type: [Network.Wai.Parse.Param]
In the second argument of `map', namely `params'
In the second argument of `($)', namely
Which is a bit odd because Network.Wai.Parse docs say that Param is a type synonym for (ByteString, ByteString), so as far as I can tell, this should work.
Any tips on what I'm doing wrong?
Your wai-extra was built using
bytestring-0.9.2.1, but you have a newerbytestringpackage installed. Unless GHC is instructed to use the older version with a-packageflag or by hiding the newer, it picks the newest installed version of each package.The package version is part of the types it defines, so the
ByteStringofbytestring-0.9.2.1is not the same type as theByteStringofbytestring-0.10.0.0(or whatever your newest version is).You can
-package bytestring-0.9.2.1flag (but it could be that other used packages are built against a differentbytestringversion, then that wouldn't work).Cabalized package, thencabal-installwould figure out the necessary-packageflags and provide them to GHC (if it finds a consistent build plan).wai-extra(and possibly a lot of other packages) against the newerbytestringversion.bytestringversion (which might require rebuilding some packages using the old version).