繁体   English   中英

如何在“ hakyll”和“ hakyll-images”之间协调类型

[英]How to reconcile types between `hakyll` and `hakyll-images`

我正在尝试使用hakyllhakyll-images来实现hakyll-images自述文件中的示例,该hakyll-images执行我需要做的图像缩放。 对于给定的示例,这些类型不统一,我正在寻求有关如何进行操作的建议。

hakyll-images自述文件的失败示例如下。

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
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

该错误是因为compile需要将loadImage定义的Image类型作为Writable类型实例的实例。 从hackage文档复制的hakyllhakyll-images使用的功能类型如下所示。

    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)

Image中定义hakyll-images作为type Image = Image_ ByteString 我不确定Image_是什么; 该文档的链接未在Hakyll.Images模块的文档中链接。

无论如何,由于Image不是Writable的实例,因此hakyll-images的自述文件中的示例似乎无法编译。 我想知道hakyll-images软件包hakyll在某个时候与hakyll不同步,从而导致示例不再编译。

这个评估看似正确吗? 您对我如何解决问题有何建议?

我正在考虑:

  • 通过以某种方式为Image添加Writable实例来更新hakyll-images
  • 使用其他功能集或功能组合来执行保留宽高比的图像缩放。
  • 抛弃hakyll-images并找到其他缩放图像的方法。

此行为是一个臭虫,已进入hakyll-images 0.3.1版本。 随后将其固定在hakyll图像0.4及更高版本中。 只需更新到最新版本即可解决此问题。

这是一个粗略的监督,并且添加了测试,因此不会再次发生。

如果您想自己实现实例,则可以在此处查看如何完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM