抢劫示例不起作用:“hcCompiledSplices”不是记录选择器

Heist example not working: ‘hcCompiledSplices’ is not a record selector

我正在尝试了解如何使用 Heist,但是 none 我发现的示例似乎有效,而且我似乎找不到其他人遇到与我相同的问题。我在这里找到了一些示例代码:

https://www.schoolofhaskell.com/school/to-infinity-and-beyond/older-but-still-interesting/compiled-heist-insight-with-no-snap-in-sight

但是,当我尝试 运行 第一个示例时,出现以下错误:

Main.hs:20:15:
    ‘hcCompiledSplices’ is not a record selector
    In the expression:
    mempty
        {hcCompiledSplices = "foo" ## splice,
        hcTemplateLocations = [loadTemplates "."]}
    In an equation for ‘heistConfig’:
        heistConfig
        = mempty
            {hcCompiledSplices = "foo" ## splice,
            hcTemplateLocations = [loadTemplates "."]}
    In the expression:
    do { let heistConfig = ...;
        heistState <- either (error "oops") id
                        <$> (runEitherT $ initHeist heistConfig);
        builder <- maybe (error "oops") fst
                    $ renderTemplate heistState "simple";
        toByteStringIO B.putStr builder }

Main.hs:22:15:
    ‘hcTemplateLocations’ is not a record selector
    In the expression:
    mempty
        {hcCompiledSplices = "foo" ## splice,
        hcTemplateLocations = [loadTemplates "."]}
    In an equation for ‘heistConfig’:
        heistConfig
        = mempty
            {hcCompiledSplices = "foo" ## splice,
            hcTemplateLocations = [loadTemplates "."]}
    In the expression:
    do { let heistConfig = ...;
        heistState <- either (error "oops") id
                        <$> (runEitherT $ initHeist heistConfig);
        builder <- maybe (error "oops") fst
                    $ renderTemplate heistState "simple";
        toByteStringIO B.putStr builder }

我做错了什么?

使用镜头似乎是现在做事的方式。

此外,我将模板 simple.tpl 更改为使用标签 <h:foo>...</h:foo> 而不仅仅是 <foo>...</foo>

{-# LANGUAGE OverloadedStrings  #-}

module Lib2 where

-- import Data.Monoid
import qualified Data.Text as T
import qualified Data.ByteString as B
import Blaze.ByteString.Builder
import Control.Monad
import Control.Monad.IO.Class
import Control.Applicative
import Control.Monad.Trans.Either
import Heist
import Heist.Compiled as C
import Control.Lens

runtime :: RuntimeSplice IO T.Text
runtime = liftIO $ do
    putStrLn "Write something:"
    T.pack <$> getLine

splice :: Splice IO
splice = return $ C.yieldRuntimeText $ runtime

main = do
    let heistConfig = emptyHeistConfig
          & hcTemplateLocations .~ [ loadTemplates "." ]
          & hcCompiledSplices .~  ( "foo" ## splice )
        reportErrors errs = error ("errors: " ++ unlines errs)
    heistState <- either reportErrors id <$> 
         (runEitherT $ initHeist heistConfig)
    builder <- maybe (error "oops") fst $
         renderTemplate heistState "simple"
    toByteStringIO B.putStr builder