代码之家  ›  专栏  ›  技术社区  ›  mherzl

如何协调“hakill”和“hakill”图像之间的类型`

  •  0
  • mherzl  · 技术社区  · 6 年前

    我想用 hakyll hakyll-images 从中实现示例 哈基尔图像 自述文件,它按照我的需要执行图像缩放。对于给定的示例,类型并不统一,我正在寻求有关如何继续的建议。

    失败的例子来自 hakyll-images Readme 在下面。

    import Hakyll
    import Hakyll.Images        ( loadImage
                                , scaleImageCompiler
                                )
    main = hakyll $ do
        -- Scale images to fit within a 600x400 box
        -- Aspect ratio will be preserved
        match "images/*" $ do
            route idRoute
            compile $ loadImage
                >>= scaleImageCompiler 600 400
    

    尝试编译时出错:

    site.hs:12:9: error:
        • No instance for (Writable
                             hakyll-images-0.3.1:Hakyll.Images.Common.Image)
            arising from a use of ‘compile’
        • In a stmt of a 'do' block:
            compile $ loadImage >>= scaleImageCompiler 600 400
          In the second argument of ‘($)’, namely
            ‘do route idRoute
                compile $ loadImage >>= scaleImageCompiler 600 400’
          In a stmt of a 'do' block:
            match "images/*"
              $ do route idRoute
                   compile $ loadImage >>= scaleImageCompiler 600 400
       |
    12 |         compile $ loadImage >>= scaleImageCompiler 600 400
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

    错误是因为类型 Image ,由 loadImage ,是必需的 compile 作为typeclass的实例 Writable . 从中使用的函数类型 哈基尔 哈基尔图像 如下所示。

        route :: Routes -> Rules ()
        idRoute :: Routes
        compile :: (Binary a, Typeable a, Writable a) => Compiler (Item a) -> Rules ()
        loadImage :: Compiler (Item Image)
        scaleImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image)
    

    图像 定义在 hakyll-images 作为 type Image = Image_ ByteString . 我不确定什么 Image_ 在该文档中没有链接 Hakyll.Images module .

    在任何情况下,该示例 哈基尔图像 的自述文件由于 图像 不是的实例 可写的 . 我想知道 哈基尔图像 包与不同步 哈基尔 在某种程度上导致示例不再编译。

    这个评估看起来正确吗? 你建议我如何解决问题?

    我正在考虑:

    • 更新 哈基尔图像 通过添加 可写的 实例为 图像 .
    • 使用其他一些函数集或函数组合来执行保持图像缩放的纵横比。
    • 挖沟 哈基尔图像 找到其他方法来缩放图像。
    1 回复  |  直到 6 年前
        1
  •  2
  •   Laurent René de Cotret    6 年前

    这种行为是一个进入Hakill Images 0.3.1版本的bug。随后在0.4及以上的Hakill图像中修复。只需更新到最新版本即可解决此问题。

    这是一个严重的监督,并且增加了一些测试,这样就不会再发生这种情况了。

    如果您想自己实现这些实例,您可以看看它是如何完成的。 here .