Commit 47875bd4 authored by Alec Theriault's avatar Alec Theriault Committed by Ryan Scott
Browse files

Add 'Lift' instances for 'NonEmpty' and 'Void'

Summary:
Since 'NonEmpty' and 'Void' are now part of 'base', it makes
sense that we put 'Lift' instances for them in 'template-haskell'.
Not doing so is going to force users to define their own (possibly
colliding) orphan instances downstream.

Test Plan: ./validate

Reviewers: goldfire, bgamari, RyanGlScott

Reviewed By: RyanGlScott

Subscribers: RyanGlScott, rwbarton, carter

GHC Trac Issues: #15961

Differential Revision: https://phabricator.haskell.org/D5391
parent 80d665a1
...@@ -34,6 +34,8 @@ import Control.Monad.IO.Class (MonadIO (..)) ...@@ -34,6 +34,8 @@ import Control.Monad.IO.Class (MonadIO (..))
import System.IO ( hPutStrLn, stderr ) import System.IO ( hPutStrLn, stderr )
import Data.Char ( isAlpha, isAlphaNum, isUpper ) import Data.Char ( isAlpha, isAlphaNum, isUpper )
import Data.Int import Data.Int
import Data.List.NonEmpty ( NonEmpty(..) )
import Data.Void ( Void, absurd )
import Data.Word import Data.Word
import Data.Ratio import Data.Ratio
import GHC.Generics ( Generic ) import GHC.Generics ( Generic )
...@@ -701,6 +703,17 @@ liftString :: String -> Q Exp ...@@ -701,6 +703,17 @@ liftString :: String -> Q Exp
-- Used in TcExpr to short-circuit the lifting for strings -- Used in TcExpr to short-circuit the lifting for strings
liftString s = return (LitE (StringL s)) liftString s = return (LitE (StringL s))
-- | @since 2.15.0.0
instance Lift a => Lift (NonEmpty a) where
lift (x :| xs) = do
x' <- lift x
xs' <- lift xs
return (InfixE (Just x') (ConE nonemptyName) (Just xs'))
-- | @since 2.15.0.0
instance Lift Void where
lift = pure . absurd
instance Lift () where instance Lift () where
lift () = return (ConE (tupleDataName 0)) lift () = return (ConE (tupleDataName 0))
...@@ -752,6 +765,9 @@ leftName, rightName :: Name ...@@ -752,6 +765,9 @@ leftName, rightName :: Name
leftName = mkNameG DataName "base" "Data.Either" "Left" leftName = mkNameG DataName "base" "Data.Either" "Left"
rightName = mkNameG DataName "base" "Data.Either" "Right" rightName = mkNameG DataName "base" "Data.Either" "Right"
nonemptyName :: Name
nonemptyName = mkNameG DataName "base" "GHC.Base" ":|"
----------------------------------------------------- -----------------------------------------------------
-- --
-- Generic Lift implementations -- Generic Lift implementations
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
`Maybe [TyVarBndrQ]` argument. Non-API-breaking versions of these `Maybe [TyVarBndrQ]` argument. Non-API-breaking versions of these
functions can be found in `Language.Haskell.TH.Lib`. functions can be found in `Language.Haskell.TH.Lib`.
* Add `Lift` instances for `NonEmpty` and `Void`
## 2.14.0.0 *TBA* ## 2.14.0.0 *TBA*
* Introduce an `addForeignFilePath` function, as well as a corresponding * Introduce an `addForeignFilePath` function, as well as a corresponding
......
...@@ -19,7 +19,7 @@ TH_localname.hs:3:11: error: ...@@ -19,7 +19,7 @@ TH_localname.hs:3:11: error:
Language.Haskell.TH.Syntax.Lift (Maybe a) Language.Haskell.TH.Syntax.Lift (Maybe a)
-- Defined in ‘Language.Haskell.TH.Syntax’ -- Defined in ‘Language.Haskell.TH.Syntax’
...plus 14 others ...plus 14 others
...plus 10 instances involving out-of-scope types ...plus 12 instances involving out-of-scope types
(use -fprint-potential-instances to see them all) (use -fprint-potential-instances to see them all)
• In the expression: Language.Haskell.TH.Syntax.lift y • In the expression: Language.Haskell.TH.Syntax.lift y
In the expression: In the expression:
......
...@@ -9,6 +9,7 @@ import Data.Ratio ...@@ -9,6 +9,7 @@ import Data.Ratio
import Data.Word import Data.Word
import Data.Int import Data.Int
import Numeric.Natural import Numeric.Natural
import Data.List.NonEmpty
a :: Integer a :: Integer
a = $( (\x -> [| x |]) (5 :: Integer) ) a = $( (\x -> [| x |]) (5 :: Integer) )
...@@ -76,4 +77,6 @@ n = $( (\x -> [| x |]) () ) ...@@ -76,4 +77,6 @@ n = $( (\x -> [| x |]) () )
o :: (Bool, Char, Int) o :: (Bool, Char, Int)
o = $( (\x -> [| x |]) (True, 'x', 4 :: Int) ) o = $( (\x -> [| x |]) (True, 'x', 4 :: Int) )
p :: NonEmpty Char
p = $( (\x -> [| x |]) ('a' :| "bcde") )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment