haskell - 如何协调`hakyll`和`hakyll-images`之间的类型
问题描述
我正在尝试使用hakyll
并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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
错误是因为Image
由 定义的typeloadImage
必须compile
是 typeclass 的实例Writable
。hakyll
从 hackage 文档中复制的和使用的函数类型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
模块的文档中链接。
无论如何,hakyll-images
由于Image
不是Writable
. 我想知道是否可能hakyll-images
包在某些时候变得不同步hakyll
导致示例不再编译。
这个评估似乎正确吗?您对我如何解决解决方案有什么建议?
我正在考虑:
- 通过
hakyll-images
以某种方式Writable
为Image
. - 使用其他一些功能集或组合来执行保持纵横比的图像缩放。
- 放弃
hakyll-images
并寻找其他方式来缩放图像。
解决方案
这种行为是一个进入 hakyll-images 0.3.1 版本的错误。随后在 hakyll-images 0.4 及更高版本中对其进行了修复。只需更新到最新版本即可解决此问题。
这是一个严重的疏忽,并且已经添加了测试,这样就不会再发生这种情况了。
如果您想自己实现这些实例,您可以在此处查看它是如何完成的。
推荐阅读
- windows - 如何将压缩文件放入 Java 程序?
- c# - ViewModel 将 null 返回到表单中,我该如何解决这个问题
- c# - 实体框架,相似但不同的数据库——我们可以在实体类之间使用继承吗?
- python - 在最小化问题中保存中间结果
- image - 在 .rst 文件中插入内联图标
- flutter - 行 mainAxisAlignment 不适用于 FittedBox
- node.js - 基于 URL 参数动态访问 Mongodb 数据库集合
- javascript - 无法根据选定的数据列表选项自动填充文本区域
- javascript - 有没有办法我可以维护从数据库中填充并出现在 asp.net 中母版页的页面加载功能上的选定菜单/子菜单
- javascript - 如何声明布尔或对象类型?