lev*_*tov 7 haskell template-haskell deriving
为什么模板Haskell忽略引用中的独立派生声明?
{-# LANGUAGE TemplateHaskell, StandaloneDeriving #-}
data Test a = Test a
$([d| deriving instance Show a => Show (Test a); f x = x |])
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
这曾经是编译器的缺点,其中声明的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开始,这个bug已经修复了.(感谢@VladimirStill在下面的评论中指出这一点.)
| 归档时间: |
|
| 查看次数: |
762 次 |
| 最近记录: |