[GHC] #15961: TH 'Lift' instance for 'NonEmpty'

GHC ghc-devs at haskell.org
Wed Nov 28 11:53:31 UTC 2018


#15961: TH 'Lift' instance for 'NonEmpty'
-------------------------------------+-------------------------------------
        Reporter:  fr33domlover      |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.6.3
       Component:  Template Haskell  |              Version:  8.6.2
      Resolution:                    |             Keywords:  lift,
                                     |  instance, nonempty
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  Other             |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by fr33domlover:

Old description:

> 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'
> }}}

New description:

 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 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 `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#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list