Вопрос

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 newer bytestring package installed. Unless GHC is instructed to use the older version with a -package flag 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 ByteString of bytestring-0.9.2.1 is not the same type as the ByteString of bytestring-0.10.0.0 (or whatever your newest version is).

You can

  • compile the programme with a -package bytestring-0.9.2.1 flag (but it could be that other used packages are built against a different bytestring version, then that wouldn't work).
  • build the programme as a Cabalized package, then cabal-install would figure out the necessary -package flags and provide them to GHC (if it finds a consistent build plan).
  • rebuild wai-extra (and possibly a lot of other packages) against the newer bytestring version.
  • unregister the newer bytestring version (which might require rebuilding some packages using the old version).
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top