readPackageDescription 和 parsePackageDescription 之间的 Cabal 包区别

Cabal package difference between readPackageDescription and parsePackageDescription

Haskell 包 Cabal-1.24.2 有模块 Distribution.PackageDescription.Parse。 模块有 2 个函数:readPackageDescription 和 parsePackageDescription。

当我在 ghci 中 运行:

let d = readPackageDescription normal "C:\somefile.cabal"

我已解析 GenericPackageDescription

但是当我在 ghci 中 运行:

content <- readFile "C:\somefile.cabal"
let d = parsePackageDescription content

我遇到解析错误:

ParseFailed (FromString "Plain fields are not allowed in between stanzas: F 2 \"version\" \"0.1.0.0\"" (Just 2))

文件示例是使用 cabal init 生成的文件

parsePackageDescription 期望将文件内容本身传递给它,而不是它们存储的文件路径。您需要先阅读文件……但要注意文件编码问题。 http://www.snoyman.com/blog/2016/12/beware-of-readfile