问题描述
我试图在编译时解析一些 markdown 并保留它生成的 Html 实例。
通常我会使用派生的 Language.Haskell.TH.Lift.Lift
实例来做这样的事情:
-- Lib.hs
module Lib where
import Language.Haskell.TH
import Language.Haskell.TH.Lift
data MyNiceType = MyNiceType { f0 :: Int } deriving (Lift,Show)
preloadNiceType :: Q Exp
preloadNiceType = do
-- do some important work at compile time
let x = MyNiceType 0
[| x |]
但是,当我使用包含 Blaze.Html 字段的类型尝试此模式时:
(我正在使用扩展 TemplateHaskell
DeriveLift
DeriveGeneric
,以及包 template-haskell
th-lift
和 blaze-html
)
data MyBadType = MyBadType { f1 :: Html } deriving (Lift)
我收到此错误:
• No instance for (Lift Html)
arising from the first field of ‘MyBadType’ (type ‘Html’)
Possible fix:
use a standalone 'deriving instance' declaration,so you can specify the instance context yourself
• When deriving the instance for (Lift MyBadType)
现在,从这个错误中很清楚 GHC 想要我做什么。但我真的会避免自己为 Html 类型实例化 Lift(或 Data)。
有什么办法可以避免吗? 或者我在这里缺少的不同方法? 或者是通过一些我不知道的技巧来实现这些实例吗?
我知道我可以在编译时将 markdown 源存储为 Text 并在运行时呈现它,但我想知道是否有替代方法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)