[GHC] #14112: bang patterns on pattern synonyms? (left vs right hand sides)
GHC
ghc-devs at haskell.org
Mon Aug 28 13:53:27 UTC 2017
#14112: bang patterns on pattern synonyms? (left vs right hand sides)
-------------------------------------+-------------------------------------
Reporter: carter | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
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 simonpj):
Ryan has it right. The syntax is
{{{
pattern P x y z = <pattern>
}}}
Hence bangs are allowed. For the implicitly-bidirectional case we have to
turn the `<pattern>` into an expression. Currently, that conversion
simply discards the bangs, which is the behaviour you are seeing.
Silently ignoring the bangs is arguably rather undesirable. (The
conversion also silently ignores a `~`, but that's probably correct
behaviour.)
It would make more sense to do one of these:
A. Reject an implicitly-bidirectional pattern with bangs, on the grounds
that it's not invertible (like view patterns, say); suggest using an
explicitly-bidirectional pattern instead.
B. Auto-generate the bang'd definition that Ryan writes above.
{{{
MkPair1 !x !y = MkPair x y
}}}
That is, in the `ImplicitBidirectional` case, if we see `!x` in the
pattern, use a `!x`, instead of `x` as the argument pattern of the
builder.
I think I prefer (B). It's easy to implement: see `mk_match_group` in
`TcPatSyn.tcPatSynBuilderBind` . You'd need to alter `tcPatToExpr` to
return the banged variables. (Ignore bangs on constructors e.g. `Just
!(Just x)`; they are no-ops.)
Don't forget to specify all this in the user manual.
Volunteers?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14112#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list