Opened 5 years ago

Closed 5 years ago

#8656 closed bug (fixed)

Identical functions in Template Haskell

Reported by: jstolarek Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I noticed that module Language.Haskell.TH.Lib in template-haskell library contains duplicate functions:

global :: Name -> ExpQ
global s = return (VarE s)

varE :: Name -> ExpQ
varE s = return (VarE s)

If this is intended it should be documented why it is so and I think it would be good to express one function in terms of another. If this is accidental we should just get rid of one function. I never used TH so I have no idea whether this is done on purpose or not, thus leaving it to devs more experienced with TH.

Change History (4)

comment:1 Changed 5 years ago by goldfire

My sense is that functions like varE (and even type synonyms like ExpQ) are present mainly to ease the implementation of the DsMeta module. That module takes quotes (like [| 1 + x |]) and converts them into Core code (like appE (appE (varE '+) (litE (integerL 1))) (varE 'x)). So, even though global exists, it's really nice to have varE so that there is regularity in these monadic functions. (Each constructor, say, of Exp has a function counterpart defined in Language.Haskell.TH.Lib.)

Whether or not it's useful to have global is another question. But, my thought is that it's best not to disrupt potential clients of that function.

I agree that it's a little silly to have both of these functions, but it doesn't seem worth changing, to me. I'm also not sure how best to document this issue. My tendency would be toward closing this ticket as "wontfix", but I'll wait for someone to second my reasoning before doing so.

comment:2 Changed 5 years ago by simonpj

I'm inclined to deprecate global. I'll do that.


comment:3 Changed 5 years ago by jstolarek

Summary: Identical functions in Templeta HaskellIdentical functions in Template Haskell

I'm also not sure how best to document this issue.

This could be documenting by explaining why we keep two identical functions, eg. varE for consistency and global to maintain API compatibility with existing code. Next person to see these two identical functions would not spend their time trying to figure out why do we have duplicate code :-)

comment:4 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed

OK I've deprecated global:

commit 6b485668ba22d4d78664866100a8ef2daf62ff89
Author: Simon Peyton Jones <>
Date:   Thu Jan 9 18:01:06 2014 +0000

    Deprecate (Trac #8656)


 Language/Haskell/TH/Lib.hs |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/Language/Haskell/TH/Lib.hs b/Language/Haskell/TH/Lib.hs index 2dfef30..b7a88d6 100644
--- a/Language/Haskell/TH/Lib.hs
+++ b/Language/Haskell/TH/Lib.hs
@@ -200,6 +200,8 @@ dyn :: String -> ExpQ  dyn s = return (VarE (mkName s))
 global :: Name -> ExpQ
+{-# DEPRECATED global "Use varE instead" #-}
+-- Trac #8656; I have no idea why this function is duplicated
 global s = return (VarE s)
 varE :: Name -> ExpQ
Note: See TracTickets for help on using tickets.