模板Haskell报价中的独立派生声明

时间:2013-01-14 10:24:43

标签: haskell template-haskell deriving

为什么模板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

1 个答案:

答案 0 :(得分:7)

这曾经是编译器的缺点,其中声明的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在下面的评论中指出这一点。)