[GHC] #15961: TH 'Lift' instance for 'NonEmpty'
#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
#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
#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: | -------------------------------------+------------------------------------- Comment (by harpocrates): Please avoid using the default `Data` implementations of `Lift` (or at least explicitly define `lift = liftData`). For existing code, I would use `-XStandaloneDeriving` and `-XDeriveLift`. {{{ deriving instance Lift a => Lift (NonEmpty a) }}} I agree we should put instances in `template-haskell` now that `NonEmpty` is in `base`. I'll put up a patch and we can see what others think. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15961#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15961: TH 'Lift' instance for 'NonEmpty' -------------------------------------+------------------------------------- Reporter: fr33domlover | Owner: (none) Type: feature request | Status: patch 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): Phab:D5391 Wiki Page: | -------------------------------------+------------------------------------- Changes (by harpocrates): * status: new => patch * differential: => Phab:D5391 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15961#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15961: TH 'Lift' instance for 'NonEmpty' -------------------------------------+------------------------------------- Reporter: fr33domlover | Owner: (none) Type: feature request | Status: patch 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): Phab:D5391 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"47875bd4d79ca633b589e63e320aa5a5c631d096/ghc" 47875bd4/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="47875bd4d79ca633b589e63e320aa5a5c631d096" 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 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15961#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15961: TH 'Lift' instance for 'NonEmpty' -------------------------------------+------------------------------------- Reporter: fr33domlover | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: 8.8.1 Component: Template Haskell | Version: 8.6.2 Resolution: fixed | 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): Phab:D5391 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed * milestone: 8.6.3 => 8.8.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15961#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC