[GHC] #15961: TH 'Lift' instance for 'NonEmpty'
GHC
ghc-devs at haskell.org
Wed Nov 28 11:11:21 UTC 2018
#15961: TH 'Lift' instance for 'NonEmpty'
-------------------------------------+-------------------------------------
Reporter: fr33domlover | Owner: (none)
Type: feature | Status: new
request |
Priority: normal | Milestone: 8.6.3
Component: Template | Version: 8.6.2
Haskell |
Keywords: lift, | Operating System: Unknown/Multiple
instance, nonempty |
Architecture: | Type of failure: Other
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
I was using `deriving Lift` on a data type and the `DeriveLift` extension:
{{{#!hs
import Data.List.NonEmpty
import Language.Haskell.TH
data T = T (NonEmpty String) Int
}}}
and I noticed I couldn't get an automatic instance because `NonEmpty`
doesn't have a `Lift` instance. I'm wondering if an instance can be added
to the `template-haskell` package (or elsewhere if that isn't the right
place? I'm assuming it is because `NonEmpty` is in `base` now)
Since `NonEmpty` has a `Data` instance, I suppose the following would be
enough?
{{{#!hs
instance Data a => Lift (NonEmpty a)
}}}
And without using `Data` it could be:
{{{#!hs
nonemptyConName :: Name
nonemptyConName = mkNameG DataName "base" "Data.List.NonEmpty" ":|"
instance Lift a => Lift (NonEmpty a) where
lift (x :| xs) = do
x' <- lift x
xs' <- traverse lift xs
return $ ConE nonemptyConName `AppE` x' `AppE` xs'
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15961>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list