[英]How to reconcile types between `hakyll` and `hakyll-images`
我正在尝试使用hakyll
和hakyll-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文档复制的hakyll
和hakyll-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.