[GHC] #10548: Support PartialTypeSignatures in Template Haskell

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.10.1 Component: Template | Operating System: Unknown/Multiple Haskell | Type of failure: None/Unknown Keywords: | Blocked By: Architecture: | Related Tickets: Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Currently Template Haskell cannot emit [https://hackage.haskell.org/package/template-haskell-2.10.0.0/docs /Language-Haskell-TH-Syntax.html#t:Type Type]s with wildcards as in [https://ghc.haskell.org/trac/ghc/wiki/PartialTypeSignatures PartialTypeSignatures]. A data constructor for wildcards (eg. {{{WildcardT (Maybe Name)}}}) could be added to [https://hackage.haskell.org/package/template- haskell-2.10.0.0/docs/Language-Haskell-TH-Syntax.html#t:Type Type], which would be converted to wildcards in GHC. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: => newcomer Comment: Adding new language features to TH is a fantastic way to start hacking on GHC. (Proof: it was my first contribution.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by spinda): I believe an implementation would consist of: (1) Add a {{{WildcardT (Maybe Name)}}} data constructor to the declaration of [https://github.com/ghc/ghc/blob/master/libraries/template- haskell/Language/Haskell/TH/Syntax.hs#L1464-L1483 Language.Haskell.TH.Syntax.Type]. (2) Add a new branch to [https://github.com/ghc/ghc/blob/058af6c90a0e8d122f2d1339b6b4fd0b5ec83d05/com... cvtTypeKind] that translates this to either [https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc/HsTypes.ht... HsWildcardTy] or [https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc/HsTypes.ht... HsNamedWildcardTy], depending on the {{{Maybe Name}}} value. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Without looking at the code myself, this sounds entirely reasonable to me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by adamgundry): * cc: thomasw, adamgundry (added) Comment: I'd also like this (see #10094). I looked at it briefly and it didn't seem to be completely trivial, because the implementation traversed types to collect wildcards prior to renaming the type, and the presence of TH type splices means that it's hard to know up front whether wildcards will be present. But 058af6c90a0e8d122f2d1339b6b4fd0b5ec83d05 may have made it easier. Perhaps thomasw can advise further? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomasw): * owner: => thomasw -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomasw): The changes to TH itself are straightforward. However Adam is right, the (named) wild cards must be known before renaming starts, and TH type splices are run ''during'' renaming. Besides a small bug I'm looking into, I see no problem with supporting anonymous wild cards in TH type splices. Named wild cards will require much more work and a refactoring of how splices and wild cards interact during renaming. Does it make sense to only allow anonymous wild cards in TH type splices but not named wild cards? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by thomasw): I forgot to add that extra-constraints wild cards (`_ => ...`) have the same problem as named wild cards: they must be known before renaming. If people are ok with only having anonymous type wild cards in TH type splices, then I'll post a diff on Phabricator. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by adamgundry): Thanks for looking at this! I can't speak for everyone, but for my use case I need only anonymous type wild cards, not named or extra-constraints wild cards. Please do post a diff. We can perhaps put off the extra work until anyone comes up with a reason for wanting the other cases... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Changes (by thomasw): * differential: => Phab:D1048 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Comment (by spinda): Ideally I'd like to see all type features accessible from TH, but this fits my use case right now. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Comment (by thomasw): Actually, this limitation only applies to type splices. I had forgotten about declaration splices, which can also contain type signatures, until goldfire reminded me. My patch on Phabricator adds full support for partial type signatures in declaration splices in addition to support for anonymous wild cards in type splices. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell
-------------------------------------+-------------------------------------
Reporter: spinda | Owner: thomasw
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Template Haskell | Version: 7.10.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D1048
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => fixed * milestone: => 7.12.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Comment (by simonpj): Are there some feature tests for this? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Comment (by thomasw): Replying to [comment:14 simonpj]:
Are there some feature tests for this?
Yes, I think I added tests for all splices, including the scenarios in which wild cards aren't supported. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Comment (by simonpj): Terrific. So can you add them to the "Test case" field of this ticket? Or if too many, list them in a comment, and in the "Test case" field say "see comment:23" of whatever? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10548: Support PartialTypeSignatures in Template Haskell -------------------------------------+------------------------------------- Reporter: spinda | Owner: thomasw Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: comment:17 Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1048 -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: => comment:17 Comment: D1048 included the following tests, * `ExtraConstraintsWildcardInExpressionSignature` * `ExtraConstraintsWildcardInPatternSignature` * `ExtraConstraintsWildcardInPatternSplice` * `ExtraConstraintsWildcardInTypeSplice` * `ExtraConstraintsWildcardInTypeSplice2` * `ExtraConstraintsWildcardInTypeSpliceUsed` * `NamedWildcardInTypeSplice` * `WildcardInTypeBrackets` -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10548#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC