[GHC] #14114: Strange behavior when pattern variables are duplicated on pattern synonym RHS
GHC
ghc-devs at haskell.org
Mon Aug 14 22:24:34 UTC 2017
#14114: Strange behavior when pattern variables are duplicated on pattern synonym
RHS
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
Keywords: | Operating System: Unknown/Multiple
PatternSynonyms |
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
These might be two separate bugs, but they're similar enough that I'll
bundle them under the same ticket.
If you take a pattern variable bound on the LHS of a unidirectional
pattern synonym and use it multiple locations on the RHS, then GHC accepts
it, surprisingly:
{{{#!hs
pattern Foo a <- (a,a)
}}}
What does `Foo` do? As it turns out, the right-most occurrence of `a` in
the RHS seems to take precedence:
{{{
λ> :i Foo
pattern Foo :: b -> (a, b) -- Defined at <interactive>:12:1
λ> case ('a', 'b') of Foo x -> x
'b'
}}}
I expect the definition of `Foo` to error.
When duplicate pattern variables are used in the RHS of an implicitly
bidirectional pattern synonym, then it does error. However, the error
message is quite misleading:
{{{
λ> pattern Foo a = (a,a)
<interactive>:16:17: error:
Invalid right-hand side of bidirectional pattern synonym ‘Foo’:
‘a’ is not bound by the LHS of the pattern synonym
RHS pattern: (a, a)
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14114>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list