[GHC] #8761: Make pattern synonyms work with Template Haskell

#8761: Make pattern synonyms work with Template Haskell ------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.8.1-rc1 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Template Haskell has no support for pattern synonyms. This should be added. Specifically: * Create syntax in `Language.Haskell.TH.Syntax` and corresponding functions in `Language.Haskell.TH.Lib` * Support in !DsMeta for desugaring pattern synonym quotations. See `rep_bind`. * Support in Convert for splicing in pattern synonyms. * Support in !TcSplice for reifying pattern synonyms. See `reifyThing`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.8.2 Component: Template Haskell | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by thoughtpolice): * version: 7.8.1-rc1 => * milestone: => 7.8.2 Comment: This isn't going to be done in time for 7.8.1 at least. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.8.2 Component: Template Haskell | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by thoughtpolice): Or, well, unless you propose to add it (very soon), Richard. :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.8.2 Component: Template Haskell | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by goldfire): No. My thought is that the TH interface should (barring some large disaster) remain stable from the RC to the released version. That way, packages that use TH can test against the RC and be confident that their code will work against the release. Even if I were to implement it today (no plans to), I wouldn't recommend merging. I created the ticket just as a reminder (to anyone) that this should be done. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Template Haskell | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by merijn): * cc: merijn@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: normal | Version: Component: Template | Keywords: pattern synonyms Haskell | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * cc: cactus (added) * keywords: => pattern synonyms -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature | Status: new request | Milestone: 7.10.1 Priority: normal | Version: Component: Template | Keywords: PatternSynonyms Haskell | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * keywords: pattern synonyms => PatternSynonyms -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by sboo): one motivation is for fixed points https://www.reddit.com/r/haskell/comments/3qrkzr/one_weird_trick_for_nicer_f... for example: {{{#!hs {-# LANGUAGE TemplateHaskell, PatternSynonyms, DeriveFunctor #-} data TreeF a r = LitF a | VarF String | BinF r Operation r deriving Functor data Operation = Add | ... makeFix ''TreeF }}} would generate: {{{#!hs type Tree a = Fix (TreeF a) pattern Lit :: a -> Tree a pattern Lit a = Fix (LitF a) pattern Var :: String -> Tree a pattern Var s = Fix (VarF s) pattern Bin :: Tree a -> Operation -> Tree a -> Tree a pattern Bin l op r = Fix (BinF l op r) }}} which would make `TreeF` as easy to use as `Tree` when using pattern matching: {{{#!hs optimize :: Tree a -> Tree a optimize (Bin (Lit x) Add (Lit y)) = Lit (x + y) optimize ... = ... }}} and still as easy when using recursion schemes: {{{#!hs evalTreeF :: Map String Integer -> TreeF Integer (Maybe Integer) -> Maybe Integer evalTreeF environment (BinF (Just l) Add (Just r)) = Just (l + r) evalTreeF ... evalTree :: Map String Integer -> Tree Integer -> Maybe Integer evalTree environment = cata (evalTreeF environment) }}} (sorry if here's the wrong place, this is my first post) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): This is the right place. Thanks for posting! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by cocreature): * cc: cocreature (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: cocreature Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by cocreature): * owner: => cocreature -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: cocreature Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bollmann): Replying to [comment:14 cocreature]: Have you been working on this cocreature? Otherwise, I'd love to take ownership of this ticket. :-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Replying to [comment:14 cocreature]:
Have you been working on this cocreature? Otherwise, I'd love to take ownership of this ticket. :-) I started working on it, but I ran out of time to finish it. I just pushed
#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by cocreature): * owner: cocreature => Comment: Replying to [comment:16 bollmann]: the [https://github.com/cocreature/ghc/tree/th-patsyns current status]. Feel free to pick it up or start from scratch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bollmann): * owner: => bollmann -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bollmann): * differential: => Phab:D1940 Comment: I added an initial version of "pattern synonym support in TH" with a couple of questions for feedback. See https://phabricator.haskell.org/D1940. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bollmann): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner: bollmann
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Template Haskell | Version:
Resolution: | Keywords:
| PatternSynonyms
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1940
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * version: => 8.0.1 * resolution: => fixed * milestone: => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Changes (by heisenbug): * cc: heisenbug (added) Comment: Any progress on this? I'd *love* to create explicitly bidirectional pattern synonyms for FPGAs from regmap files. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:23 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): No, I don't think there is any chance of a back port. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner: bollmann
Type: feature request | Status: closed
Priority: normal | Milestone: 8.2.1
Component: Template Haskell | Version: 8.0.1
Resolution: fixed | Keywords:
| PatternSynonyms
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1940
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#8761: Make pattern synonyms work with Template Haskell
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner: bollmann
Type: feature request | Status: closed
Priority: normal | Milestone: 8.2.1
Component: Template Haskell | Version: 8.0.1
Resolution: fixed | Keywords:
| PatternSynonyms
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1940
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by heisenbug): Not sure how it is supposed to work, but can I somehow pass a name to be spliced into a pattern synonym quote? {{{#!haskell :t \n -> [d| pattern $(n) = 42 |] }}} errors out (unfortunately). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:27 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Replying to [comment:27 heisenbug]:
Not sure how it is supposed to work, but can I somehow pass a name to be spliced into a pattern synonym quote? {{{#!haskell :t \n -> [d| pattern $(n) = 42 |] }}} errors out (unfortunately).
No, I don't believe that's possible, because TH doesn't allow "name splices". You'd have to build up the syntax manually, using the `Dec` constructors or the functions from `Language.Haskell.TH.Lib`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:28 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by heisenbug): Replying to [comment:28 goldfire]:
Replying to [comment:27 heisenbug]:
''snip'' No, I don't believe that's possible, because TH doesn't allow "name splices". You'd have to build up the syntax manually, using the `Dec` constructors or the functions from `Language.Haskell.TH.Lib`.
Oh, sure. I'd build as much as possible using a quote and then alter the name by a transformation on the ADT. {{{#!haskell Prelude Language.Haskell.TH> runQ [d| pattern Foo <- 42 where Foo = 43 |] [PatSynD Foo_0 (PrefixPatSyn []) (ExplBidir [Clause [] (NormalB (LitE (IntegerL 43))) []]) (LitP (IntegerL 42))] }}} Swapping out the `Foo_0` looks easy. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:29 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by magesh.b): Is possible to extend this feature to support generating COMPLETE pragma #8779, if #8779 is going to land in 8.2 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:30 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8761: Make pattern synonyms work with Template Haskell -------------------------------------+------------------------------------- Reporter: goldfire | Owner: bollmann Type: feature request | Status: closed Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 8.0.1 Resolution: fixed | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1940 Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Please open a new ticket and assign me to it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8761#comment:31 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC