我在玩 Hakyll 并试图理解为什么它不能编译我在下面的代码片段中使用 let 语句的原因:
main :: IO ()
main = hakyll $ do
-- some other matches
match "index.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "index.html"
let indexCtx =
listField "posts" postCtx (return posts) <>
constField "title" "Home" <>
defaultContext
getResourceBody
>>= applyAsTemplate defaultContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
我在这里尝试做的只是编译简单的 index.html 模板。对我来说似乎很奇怪的是,当我删除 let 语句时它不会编译。然后 GHCi 开始抱怨:
• No instance for (base-4.12.0.0:Data.Typeable.Internal.Typeable
a0)
arising from a use of ‘loadAll’
• In the second argument of ‘(=<<)’, namely ‘loadAll "index.html"’
In a stmt of a 'do' block:
posts <- recentFirst =<< loadAll "index.html"
In the second argument of ‘($)’, namely
‘do posts <- recentFirst =<< loadAll "index.html"
getResourceBody >>= applyAsTemplate defaultContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls’
据我所知, let 语句不应该以任何方式推断行为,因为indexCtx
它甚至没有在其他地方使用。