How to get variable name in haskell

haskell

Solution

Here's the TH solution augustss mentioned:

{-# LANGUAGE TemplateHaskell #-}
module Pr where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

pr :: Name -> ExpQ
pr n = [| putStrLn ( $(lift (nameBase n ++ " = ")) ++ show $(varE n) ) |]

then in another module:

{-# LANGUAGE TemplateHaskell #-}
import Pr
a = "hello"
main = $(pr 'a)

Problem

I came to haskell having some c background knowledge and wondering is there an analog to ``` #define print( a ) printf( "%s = %d\n", #a, a ) int a = 5; print( a ); ``` that should print ``` a = 5 ``` ?

Original source