小编klr*_*lrr的帖子

ByteString to lazy Text and vice versa

I got problems with turning ByteString's into Text and vice versa. Here's the code:

{-# 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 …
Run Code Online (Sandbox Code Playgroud)

text haskell types bytestring

4
推荐指数
1
解决办法
3042
查看次数

标签 统计

bytestring ×1

haskell ×1

text ×1

types ×1