Standalone deriving declaration in Template Haskell quotation
Asked Answered
J

1

7

Why Template Haskell ignores standalone deriving declaration in quotation?

{-# 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
Jealousy answered 14/1, 2013 at 10:24 Comment(0)
D
7

This used to be a shortcoming of the compiler, where the Template Haskell datatype for declarations is not even capable of storing a stand-alone deriving instance (see http://hackage.haskell.org/packages/archive/template-haskell/2.8.0.0/doc/html/Language-Haskell-TH-Syntax.html#t:Dec).

Since 7.10, though, this bug has been fixed. (Thanks to @VladimirStill for pointing this out in a comment below.)

Diggings answered 14/1, 2013 at 11:49 Comment(2)
True, I noticed the absence of standalone deriving costructor in the library. Was hoping to get it through quotations.Jealousy
I suspect this is because standalone deriving happens in an earlier compile phase than Template Haskell. In the renamer instead of the typechecker, or something.Fariss

© 2022 - 2024 — McMap. All rights reserved.