Skip to content

How are bytestrings encoded? #134

@unhammer

Description

@unhammer
λ> let bø = [fmt|ø|] :: ByteString; in T.putStrLn $ "ø vs " <> [fmt|{T.decodeUtf8With T.lenientDecode bø}|]
ø vs �

λ> ([fmt|ø|]:: ByteString, T.encodeUtf8 "ø")
("\248","\195\184")


λ> ([fmt|{T.pack "ø"}|]:: ByteString, T.encodeUtf8 "ø")
("\248","\195\184")

("ø" in UTF-8 is 0xC3 0xB8 which is 195 184)

Does fmt encode bytestrings using some other encoding?


My current workaround is to restrict it to text

{-# LANGUAGE TemplateHaskell #-}
module PyF.Foo where
import Language.Haskell.TH.Quote
import Data.Text qualified as T
import PyF
import PyF.Internal.QQ (Config (..))
t :: QuasiQuoter
t =
  mkFormatter
    "t"
    ( fmtConfig
        { postProcess = \e -> [|T.pack $(e)|]
        }
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions