我正在尝试使用hakyll和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类型是由loadImage定义的,compile需要它作为类型Writable的一个实例。从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失去了同步,从而导致示例不再编译。
这个评估似乎正确吗?你对我如何解决这个问题有什么建议?
我正在考虑:
hakyll-images添加一个Writable实例来更新Image。hakyll-images,寻找其他方法来缩放图像。发布于 2019-01-22 01:46:31
这种行为是一个错误,它进入了hakyll图像0.3.1发行版。它随后在哈基尔-图像0.4及以上的固定。只需更新到最新版本,以解决此问题。
这是一个严重的疏忽,并增加了测试,使这种情况不会再次发生。
如果您想自己实现这些实例,可以查看它是如何实现这里的。
https://stackoverflow.com/questions/54274208
复制相似问题