mysql - 实例 (Param B.ByteString) 是如何消失的?

标签 mysql haskell cabal

我有一些以前可以编译的旧代码,但现在不能了。我担心我可能遇到了包管理问题,而且我真的很不擅长处理这类事情。我已将其简化为一个最小的失败示例。

{-# LANGUAGE OverloadedStrings #-}

module Gremlin where

import Database.MySQL.Simple.Param
import qualified Data.ByteString as SB

foo :: Param x => [x]
foo = []

shoo :: [SB.ByteString]
shoo = foo

我得到的错误是

/.../Gremlin.hs:12:8:
No instance for (Param SB.ByteString) arising from a use of ‘foo’
In the expression: foo
In an equation for ‘shoo’: shoo = foo

但是当我查看源代码时

module Database.MySQL.Simple.Param
    (
      Action(..)
    , Param(..)
    , inQuotes
    ) where

我明白了

import qualified Data.ByteString as SB

instance Param SB.ByteString where
    render = Escape
    {-# INLINE render #-}

相关版本信息可能包括

$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 7.10.2
$ ghc-pkg latest mysql-simple
mysql-simple-0.2.2.5
$ ghc-pkg latest bytestring
bytestring-0.10.8.1

当我询问 ghci 时

:info Param

我得到的列表比我预期的 mysql-simple 文档要短。

Prelude> :m + Database.MySQL.Simple.Param Data.ByteString
Prelude Database.MySQL.Simple.Param Data.ByteString> :info Param
class Param a where
  render :: a -> Action  
    -- Defined in ‘Database.MySQL.Simple.Param’
instance Param [Char] -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Word -- Defined in ‘Database.MySQL.Simple.Param’
instance Param a => Param (Maybe a)
  -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Integer -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Int -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Float -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Double -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Bool -- Defined in ‘Database.MySQL.Simple.Param’
instance Param Action -- Defined in ‘Database.MySQL.Simple.Param’

但我想这只会告诉我局部范围内的实例。然后我做

Prelude Database.MySQL.Simple.Param Data.ByteString> :m +Data.Text
Prelude Database.MySQL.Simple.Param Data.ByteString Data.Text> :info Param
class Param a where
...
instance Param Text -- Defined in ‘Database.MySQL.Simple.Param’
...

进一步调查指出了潜在的问题来源:

$ ghc-pkg describe mysql-simple
name: mysql-simple
version: 0.2.2.5
...
depends:
...
    bytestring-0.10.6.0-6e8453cb70b477776f26900f41a5e17a
...

我猜测带有实例的 ByteString 来自 0.10.6.0 并且不同于我在源文件中写入完全相同的导入时得到的版本。如果是这样,我对我必须做多少工作才能找到它感到有点恼火:如果“没有 Foo 的实例”会添加“即使有一个完整的其他 Foo 的实例”,那就太好了。

这是 cabal 的 hell ,对吧?我可以用较新的版本重建 mysql-simple 吗?我试过 ghc-pkg unregister mysql-simple 然后 cabal install mysql-simple,但无济于事。

什么是好的修复策略?

最佳答案

What's a good repair strategy?

我强烈建议您对代码进行 cabalize 并使用 cabal 沙箱或 stack。它应该首先防止这个问题。要修复,你应该找出安装了两次的包(它似乎是bytestring)并注销它。

I'm a bit peeved at how much work I had to do to find that out: it would be great if "No instance for Foo" would add "even though there's an instance for a whole other Foo".

know你感觉到什么。还好已经是fixed , 所以你应该从 ghc-8

得到更好的错误信息

关于mysql - 实例 (Param B.ByteString) 是如何消失的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293599/

相关文章:

haskell - QuickCheck 实例在 cabal 包中属于哪里?

MySQL 按列值分组 block ,按其他列排序

php - 选择将在其中返回新位置列的查询

MySQL 加入循环引用查询

haskell - `loeb` 函数还能用来做什么?

haskell - 在 cabal 沙盒中使用 Fay

mysql - 错误 2006 MySQL 服务器已消失并带有 8GB 文件

haskell - 为什么函数 concat 使用 foldr?为什么不折叠'

haskell - 我可以在不过分宽容的情况下自动为转换函数生成类型类实例吗?

haskell - Stack 尚未使用 GHC 和 Cabal 版本进行测试