[GHC] #9793: Some as-patterns could be accepted in pattern synonyms

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler (Type | Version: 7.8.3 checker) | Operating System: Keywords: pattern synonyms | Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Difficulty: Easy (less than 1 | None/Unknown hour) | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Currently all as-patterns are rejected in pattern synonym definitions, to avoid situations like {{{ pattern P x y <- x@(y:_) }}} since there's no valid reason to be able to then write something like {{{ f [True] False = ... }}} this would just lead to confusion. However, I think we could accept as-patterns where the body of the as- pattern doesn't contain any variable bindings that are accessible via the pattern synonym. In other words, this should be OK: {{{ pattern P x <- x@(y:_) }}} since it's exactly equivalent to {{{ pattern P x <- x@(_:_) }}} which I don't think is as confusing as the other example. I haven't really made up my mind yet if these should be bidirectional; but they certainly could be, by just ignoring the body of the as-pattern in the wrapper; so the following two would be equivalent: {{{ pattern P1 x = [x@(y:_)] pattern P2 x <- [x@(y:_)] where P2 x = [x] }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: feature | Status: new request | Milestone: 7.10.1 Priority: normal | Version: 7.8.3 Component: Compiler | Keywords: PatternSynonyms (Type checker) | Architecture: Unknown/Multiple Resolution: | Difficulty: Easy (less than 1 Operating System: | hour) Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cactus): * keywords: pattern synonyms => PatternSynonyms -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * status: new => patch * differential: => Phab:D1666 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Hang on. What is the ''design'' here? Specifically, what is the semantics of matching? To put it another way, suppose I have {{{ pattern P x <- x@(Right _) }}} What does it mean to match against ''that''? Well, to a first approximation, in a pattern, `P pat` means the same as `<rhs of P> with pat instead of x`. So {{{ f (P (Left y)) = e }}} means {{{ f ((Left y)@(Right _)) = e }}} And what does ''that'' mean? Perhaps we could expand the semantics of as-patterns to be `p1 @ p2`, meaning match against ''both'' `p1` ''and'' `p1`. An "and-pattern" if you like. Now everything would be well-specified. And I suppose you could say things like {{{ f ((\xs -> length xs < 10) -> True)@(y:_) = ... }}} which would match against a list of length shorter than 10, and then bind 'y' to the head of that list. But this is a bigger change, and not directly related to pattern synonyms. So far I'm unconvinced. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms
-------------------------------------+-------------------------------------
Reporter: cactus | Owner: cactus
Type: feature request | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Compiler (Type | Version: 7.8.3
checker) | Keywords:
Resolution: | PatternSynonyms
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1666
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: cactus Type: feature request | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * milestone: 8.0.1 => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: feature request | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: cactus => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: feature request | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms, newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * keywords: PatternSynonyms => PatternSynonyms, newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms, newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => new -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * keywords: PatternSynonyms, newcomer => PatternSynonyms * milestone: 8.2.1 => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Comment (by typedrat): I'm running up against this right now, and while the idea of contributing to GHC (especially with what may be a non-trivial first submitted change) is daunting, I'd be happy to at least try and do it if a design is decided on. Generally, my use case is trying to fake impredicative types in the specific application of GADT phantom types, and being able to just erase the existential wrapper from view and make it look like perfectly normal pattern matching when it's actually being taken apart would make it "feel" a lot nicer, in my opinion. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): See https://github.com/ghc-proposals/ghc-proposals/pull/94, where I propose loosening the rules for as-patterns. Perhaps your use-case would strengthen the case. Can you explain it with code? (You could do so here, and then add a comment to the proposal thread pointing to it._ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: fixed | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | patsyn/should_fail/as-pattern Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * testcase: => patsyn/should_fail/as-pattern * resolution: => fixed Comment: This was implemented in commit 411a97e2c0083529b4259d0cad8f453bae110dee. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9793: Some as-patterns could be accepted in pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: fixed | PatternSynonyms GHCProposal Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | patsyn/should_fail/as-pattern Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1666 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: PatternSynonyms => PatternSynonyms GHCProposal -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9793#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC