使用let语句时,Hakyll代码段无法编译

时间:2019-01-26 16:47:59

标签: haskell hakyll

我正在与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’

据我所知,因为indexCtx甚至没有在其他地方使用,所以let语句不应以任何方式推断行为。

0 个答案:

没有答案