У меня проблемы с превращением ByteString в текст и наоборот. Вот код:
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Web.ClientSession
import Data.Text.Lazy (Text, toStrict, fromStrict)
import Data.Text.Lazy.Encoding (encodeUtf8, decodeUtf8)
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
initCookies :: IO (Text -> ActionM ())
initCookies = do
key <- getDefaultKey
return $ setCookie key
where
setCookie k id = encryptIO k (encode id)
>>= (\x -> header "Set-Cookie" ("sid=" <> decode x <> ";"))
encode :: Text -> ByteString
encode = encodeUtf8 . toStrict
decode :: ByteString -> Text
decode = fromStrict . decodeUtf8
и сообщение об ошибке:
foo.hs:16:35:
Couldn't match expected type `bytestring-0.10.0.2:Data.ByteString.Internal.ByteString'
with actual type `ByteString'
In the return type of a call of `encode'
In the second argument of `encryptIO', namely `(encode id)'
In the first argument of `(>>=)', namely `encryptIO k (encode id)'
foo.hs:17:18:
Couldn't match type `ActionM' with `IO'
Expected type: IO ()
Actual type: ActionM ()
In the return type of a call of `header'
In the expression: header "Set-Cookie" ("sid=" <> decode x <> ";")
In the second argument of `(>>=)', namely
`(\ x -> header "Set-Cookie" ("sid=" <> decode x <> ";"))'
foo.hs:17:56:
Couldn't match expected type `ByteString'
with actual type `bytestring-0.10.0.2:Data.ByteString.Internal.ByteString'
In the first argument of `decode', namely `x'
In the first argument of `(<>)', namely `decode x'
In the second argument of `(<>)', namely `decode x <> ";"'
Итак, я предполагаю, что эта ошибка имеет какое-то отношение к тому, что на самом деле использует ClientSession, в своем исходном коде они, похоже, используют обычную байтовую строку, которая должна работать с моей реализацией. Смотри сюда:
[..]
import qualified Data.ByteString as S
[..]
encryptIO :: Key -> S.ByteString -> IO S.ByteString
[..]
Так почему я получаю все эти ошибки? Спасибо.
ghc
сообщение об ошибке содержит полностью определенный тип с именем пакета, напримерbytestring-0.10.0.2:Data.ByteString.Internal.ByteString
, то на 99% ваш пакет косвенно зависит от двух разных версий пакета. Предположение @bennofs, скорее всего, верное. Опубликовать выводghc-pkg list bytestring
- person Yuras   schedule 12.09.2013