1

I do not understand why the DuplicateRecordFields language pragma is causing a compile time error in a template haskell splice.

Example:

-- TypeModule.hs
{-# LANGUAGE DuplicateRecordFields #-}

module TypeModule where

data A = A {foo :: Int} deriving Show


-- ThModule.hs
{-# LANGUAGE TemplateHaskell #-}

module ThModule where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import TypeModule
mkLambda :: Q [Dec]
mkLambda = [d| func :: A -> Int; func = foo |]


-- Lib.hs
module Lib where

import TypeModule
import ThModule

$mkLambda
{-
    Illegal variable name: ‘$sel:foo:A’
    When splicing a TH declaration: func_0 = (TypeModule.$sel:foo:A)
  |
8 | $mkLambda
  |  ^^^^^^^^
-}

When I remove the DuplicateRecordFields pragma, the compile time error goes away. I am using the DuplicateRecordFields pragma because I am parsing a number of different JSON objects which are responses from a REST API, and many of these JSON objects contain fields with identical names.

Right now I am looking for a way that does not use DuplicateRecordFields, but at the least I would like to understand what in particular is causing the compiler trouble.

1 Answers1

0

This seems to be a known GHC issue: https://gitlab.haskell.org/ghc/ghc/-/issues/14848

Noughtmare
  • 9,410
  • 1
  • 12
  • 38