Haskell 如何协调“hakyll”和“hakyll”图像之间的类型`
我正在尝试使用并实现一个来自Haskell 如何协调“hakyll”和“hakyll”图像之间的类型`,haskell,hakyll,Haskell,Hakyll,我正在尝试使用并实现一个来自hakyll images自述文件的示例,该自述文件执行图像缩放,我需要这样做。对于给定的示例,类型不统一,我正在寻求如何继续的建议 下面是一个失败的例子 import Hakyll import Hakyll.Images ( loadImage , scaleImageCompiler ) main = hakyll $ do --
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
该错误是因为由loadImage
定义的类型Image
,是compile
所要求的类型类writeable
的实例。从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
在中定义为type Image=Image\uu.ByteString
。
我不确定什么是图像
;其定义未在该文档中链接
在任何情况下,hakyll images
自述文件中的示例似乎都没有编译,因为Image
不是可写的
的实例。我想知道是否在某个时候,hakyll-images
包与hakyll
不同步,导致示例不再编译
这个评估似乎正确吗?
您有什么建议,我可以如何找到解决方案
我正在考虑:
- 通过为
添加一个Image
实例来更新writeable
hakyll图像
- 使用其他函数集或函数组合来执行保持纵横比的图像缩放
- 挖沟
,并找到其他方法缩放图像hakyll图像
如果您想自己实现这些实例,您可以看看它是如何实现的。这种行为是hakyll images 0.3.1版本中的一个bug。随后在hakyll图像0.4及以上中对其进行了修复。只需更新到最新版本即可解决此问题 这是一个严重的疏忽,已经添加了测试,这样就不会再发生这种情况
如果您想自己实现这些实例,可以看看是如何实现的。啊,我知道我使用的是较旧的版本,它在最新版本中得到了修复。非常感谢。啊,我知道我用的是旧版本,最新版本已经修复了。非常感谢。