【问题标题】:Standalone deriving declaration in Template Haskell quotation模板 Haskell 引用中的独立派生声明
【发布时间】:2012-12-28 07:22:33
【问题描述】:

为什么 Template Haskell 会忽略引用中的独立派生声明?

{-# LANGUAGE TemplateHaskell, StandaloneDeriving #-}
data Test a = Test a
$([d| deriving instance Show a => Show (Test a); f x = x |])
ghci> :l Test.hs 
[1 of 1] Compiling Main             ( Test.hs, interpreted )
Ok, modules loaded: Main.
ghci> :t f
f :: t -> t
ghci> Test 1 :: Test Int

<interactive>:18:1:
    No instance for (Show (Test Int)) arising from a use of `print'
    Possible fix: add an instance declaration for (Show (Test Int))
    In a stmt of an interactive GHCi command: print it

【问题讨论】:

    标签: haskell template-haskell deriving


    【解决方案1】:

    这曾经是编译器的一个缺点,其中用于声明的 Template Haskell 数据类型甚至无法存储独立的派生实例(请参阅http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH-Syntax.html#t:Dec)。

    不过,自 7.10 起,this bug 已得到修复。 (感谢@VladimirStill 在下面的评论中指出这一点。)

    【讨论】:

    • 没错,我注意到库中没有独立的派生构造函数。希望通过报价得到它。
    • 我怀疑这是因为独立派生发生在比 Template Haskell 更早的编译阶段。在重命名器而不是类型检查器中,或其他东西。
    猜你喜欢
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 2011-04-02
    • 2021-05-28
    • 2013-08-12
    • 1970-01-01
    相关资源
    最近更新 更多