我可能在依赖性问题上遇到了一些麻烦,但并不完全确定。这是我的问题。我正在使用 Data.Bson 库,并将一些(文本,文本)元组转换为 bson 字段,当我定义此函数时:
typeMismatch :: (Text, Text) -> Field
typeMismatch tp = (fst tp) := (String (snd tp))
它提示:
Couldn't match expected type `Label' with actual type `Text'
Expected type: (Label, b0)
Actual type: (Text, Text)
Field
基本上只是 Bson 中的一个键/值,其中键是一个 Label
,定义为 Text
的同义词,并且value 是 Value
,String
是其众多构造函数之一(即这不是 Prelude.String
)。现在我尝试将第一个文本更改为标签:
typeMismatch :: (Label, Text) -> Field
typeMismatch tp = (fst tp) := (String (snd tp))
所以标签匹配,虽然这不是我想要的,我这样做只是为了调查,但它仍然提示:
Couldn't match expected type `text-0.11.2.0:Data.Text.Internal.Text'
with actual type `Text'
Expected type: (Label, text-0.11.2.0:Data.Text.Internal.Text)
Actual type: (Label, Text)
看起来我有一些依赖性问题或模块导入问题。但我检查了我的库,似乎 bson 使用 text-0.11.2.0 并且 data.text 也只是 text-0.11.2.0,所以一切都应该一致。
如何解决这个问题?提前致谢。
编辑:已解决。编译时通过添加“-v”标志来检查依赖关系。由于某种原因,还有 text-0.11.2.2 潜伏在某处。 ghc-pkg 取消注册该包并进行编译。从现在开始我需要开始学习如何避免“haskell 依赖 hell ”。
最佳答案
在大多数情况下,您可以使用 cabal-dev
并在 .cabal
文件中指定软件包版本来避免依赖 hell 。
关于Haskell:如何解决可能的版本冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957974/