
#5144: Pattern synonyms -------------------------------------+------------------------------------ Reporter: simonpj | Owner: cactus Type: feature request | Status: new Priority: normal | Milestone: _|_ Component: Compiler | 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 cactus): Exports now work with the following syntax: {{{ module Foo (pattern P) where pattern P x y = (x, y, 42) }}} This exports `P` both as a pattern and as an expression (if it's bidirectional, like in the case here) The extra `pattern` keyword is needed because pattern names live in the constructor namespace, so it's perfectly valid to have {{{ data P = C pattern P = () }}} (due to entirely non-interesting reasons, the implementation of exporting is not yet pushed to https://github.com/gergoerdi/ghc/tree/pattern- synonyms) Remaining work to do: * Sort out recursive pattern definitions. Currently these are rejected implicitly by an internal GHC error, not exactly ideal... also, non- recursive usages of pattern synonyms mentioning each other don't work, but I see no reason why we wouldn't want to allow it: {{{ pattern P1 = P2 pattern P2 = () }}} * The typechecker for pattern synonym definitions is wrong: it returns monomorphic types (e.g. for `pattern Head x = x:_`, it infers type `t -> [t]` instead of `forall a. a -> [a]`. This is worked around by a horrible hack when typechecking pattern synonym usages in patterns. Richard Eisenberg and Simon Peyton Jones have already offered to help with this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/5144#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler