summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2015-05-04 16:10:05 -0700
committerEdward Z. Yang <ezyang@cs.stanford.edu>2015-05-11 09:09:22 -0700
commitf16ddcee0c64a92ab911a7841a8cf64e3ac671fd (patch)
tree3427379f02f5cd3cd53704b5fa35695fd9b5e3aa /libraries
parentecc3d6be218b1c7a36ee3f2f36c4f3ac4f45c34f (diff)
downloadhaskell-f16ddcee0c64a92ab911a7841a8cf64e3ac671fd.tar.gz
Support stage 1 Template Haskell (non-quasi) quotes, fixes #10382.
Summary: This commit adds stage 1 support for Template Haskell quoting, e.g. [| ... expr ... |], which is useful for authors of quasiquoter libraries that do not actually need splices. The TemplateHaskell extension now does not unconditionally fail; it only fails if the renamer encounters a splice that it can't run. In order to make sure the referenced data structures are consistent, template-haskell is now a boot library. There are some minor BC changes to template-haskell to make it boot on GHC 7.8. Note for reviewer: big diff changes are simply code being moved out of an ifdef; there was no other substantive change to that code. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: simonpj, austin, goldfire Subscribers: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D876 GHC Trac Issues: #10382
Diffstat (limited to 'libraries')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/PprLib.hs5
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs13
-rw-r--r--libraries/template-haskell/template-haskell.cabal9
3 files changed, 22 insertions, 5 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
index a6b923cc35..68134965a5 100644
--- a/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/PprLib.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE CPP, FlexibleInstances #-}
-- | Monadic front-end to Text.PrettyPrint
@@ -41,6 +41,9 @@ import qualified Text.PrettyPrint as HPJ
import Control.Monad (liftM, liftM2, ap)
import Language.Haskell.TH.Lib.Map ( Map )
import qualified Language.Haskell.TH.Lib.Map as Map ( lookup, insert, empty )
+#if __GLASGOW_HASKELL__ < 709
+import Control.Applicative( Applicative(..) )
+#endif
infixl 6 <>
infixl 6 <+>
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 29be27a9a2..8879c62d19 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -1,6 +1,10 @@
{-# LANGUAGE CPP, DeriveDataTypeable, PolymorphicComponents,
RoleAnnotations, DeriveGeneric, FlexibleInstances #-}
+#if MIN_VERSION_base(4,8,0)
+#define HAS_NATURAL
+#endif
+
-----------------------------------------------------------------------------
-- |
-- Module : Language.Haskell.Syntax
@@ -29,16 +33,19 @@ import Data.Char ( isAlpha, isAlphaNum, isUpper )
import Data.Int
import Data.Word
import Data.Ratio
-import Numeric.Natural
import GHC.Generics ( Generic )
+#ifdef HAS_NATURAL
+import Numeric.Natural
+#endif
+
-----------------------------------------------------
--
-- The Quasi class
--
-----------------------------------------------------
-class Monad m => Quasi m where
+class (Applicative m, Monad m) => Quasi m where
qNewName :: String -> m Name
-- ^ Fresh names
@@ -487,8 +494,10 @@ instance Lift Word32 where
instance Lift Word64 where
lift x = return (LitE (IntegerL (fromIntegral x)))
+#ifdef HAS_NATURAL
instance Lift Natural where
lift x = return (LitE (IntegerL (fromIntegral x)))
+#endif
instance Integral a => Lift (Ratio a) where
lift x = return (LitE (RationalL (toRational x)))
diff --git a/libraries/template-haskell/template-haskell.cabal b/libraries/template-haskell/template-haskell.cabal
index 1c53af392e..bd277d127c 100644
--- a/libraries/template-haskell/template-haskell.cabal
+++ b/libraries/template-haskell/template-haskell.cabal
@@ -48,9 +48,14 @@ Library
Language.Haskell.TH.Lib.Map
build-depends:
- base == 4.8.*,
+ base >= 4.7 && < 4.9,
pretty == 1.1.*
-- We need to set the package key to template-haskell (without a
-- version number) as it's magic.
- ghc-options: -Wall -this-package-key template-haskell
+ ghc-options: -Wall
+
+ if impl( ghc >= 7.9 )
+ ghc-options: -this-package-key template-haskell
+ else
+ ghc-options: -package-name template-haskell