TH 'Lift' instance for 'NonEmpty'
I was using
deriving Lift on a data type and the
import Data.List.NonEmpty import Language.Haskell.TH data T = T (NonEmpty String) Int deriving Lift
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
NonEmpty has a
Data instance, I suppose the following would be enough?
instance Data a => Lift (NonEmpty a)
And without using
Data it could be:
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'