无法编译 haskell 编码库。找不到 HaXml 模块

Can't compile haskell encoding lib. Couldn't find HaXml modules

我需要一个库来编码 cp1251 中的数据,以便与使用它的 api 一起工作。

我只找到了 2 个用于此目的的库。 encoding lib and text-icu 库。第一个看起来更好,因为它可以静态链接到我的程序。

可是我连编译都不会!我正在使用堆栈,所以我将 encoding 添加到我的 .cabal 文件中的 build-deps,然后堆栈求解器使用 extra-deps 中的 encoding-0.8 更新我的堆栈 yaml 文件。

但是在 运行 stack build 之后我得到了一个错误

Data/Encoding/Preprocessor/XMLMapping.hs:11:8:
    Could not find module ‘Text.XML.HaXml.Types’
    Use -v to see a list of the files searched for.

Data/Encoding/Preprocessor/XMLMappingBuilder.hs:15:8:
    Could not find module ‘Text.XML.HaXml.OneOfN’
    Use -v to see a list of the files searched for.

Data/Encoding/Preprocessor/XMLMappingBuilder.hs:16:8:
    Could not find module ‘Text.XML.HaXml.XmlContent’
    Use -v to see a list of the files searched for.

我尝试使用旧版本的 HaXml 和编码,但遇到了同样的错误。 例如,在阅读变更日志 https://hackage.haskell.org/package/encoding-0.7.0.2/changelog 后,我尝试将 encoding-0.6.7HaXml-1.22.3 一起使用,但得到了同样的错误。 在 hackage 文档中,所有这些编码无法导入的模块都存在。

如何编译这个库?我在 linux mint x64

上使用堆栈 1.0.4、lts-5.6 和 ghc-7.10.3

stack.yaml

flags: {}
extra-package-dbs: []
packages:
- '.'
extra-deps:
- encoding-0.8
- text-1.2.2.0
resolver: lts-5.6

阴谋集团:

name:                hapidry
version:             0.1.1.0
synopsis:            Initial project template from stack
description:         Please see README.md
homepage:            -
license:             GPL-2
license-file:        LICENSE
author:              -
maintainer:          -
copyright:           GPL
category:            network
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

library
  hs-source-dirs:      src
  exposed-modules:     Lib
  build-depends:       base >= 4.7 && < 5
  default-language:    Haskell2010

executable hapidry-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , hapidry
                     , wreq
                     , ConfigFile
                     , aeson
                     , lens
                     , cryptohash
                     , binary
                     , mtl
                     , base16-bytestring
                     , bytestring
                     , containers
                     , text
                     , lens-aeson
                     , data-default
                     , optparse-applicative
                     , encoding
  default-language:    Haskell2010

test-suite hapidry-test
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             Spec.hs
  build-depends:       base
                     , hapidry
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  default-language:    Haskell2010

source-repository head
  type:     git
  location: -

终于写了自己的编码函数。它看起来像是可以接受的解决方法。另一种单字节编码的功能可以用同样的方式实现。

toCP1251 :: Text -> B.ByteString
toCP1251 = B.pack . T.unpack . T.map replace where
  replace l = case (Map.lookup l table) of
      (Just x) -> x
      (Nothing) -> l

  table = Map.fromList $ zip rus cpCodes
  cpCodes = map toEnum (168:184:[192 .. 255]) :: [Char]
  rus =  ['Ё', 'ё', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М',
         'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы',
         'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к',
         'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ',
         'ъ', 'ы', 'ь', 'э', 'ю', 'я']  :: [Char]