[GHC] #10653: PatternSynonyms should be imported/exported as part of the wildcard notation

GHC ghc-devs at haskell.org
Mon Sep 28 07:42:47 UTC 2015


#10653: PatternSynonyms should be imported/exported as part of the wildcard
notation
-------------------------------------+-------------------------------------
        Reporter:  gridaphobe        |                Owner:  mpickering
            Type:  feature request   |               Status:  new
        Priority:  high              |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.11
      Resolution:                    |             Keywords:
                                     |  PatternSynonyms, pattern synonyms
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D1258
-------------------------------------+-------------------------------------
Description changed by simonpj:

Old description:

> Suppose I have the following two modules.
>
> {{{#!hs
> {-# LANGUAGE PatternSynonyms #-}
> module A where
>
> data A = A2 Int Int
>
> pattern A1 a <- A2 a _ where
>   A1 a = A2 a 0
> }}}
> {{{#!hs
> module B where
>
> import A ( A(..) )
>
> a = A1 0
> }}}
>
> When I try to compile `B.hs` I get an error because `A1` is unbound in
> module `B`.
>
> {{{
> $ ghc --make B.hs
> [1 of 2] Compiling A                ( A.hs, A.o )
> [2 of 2] Compiling B                ( B.hs, B.o )
>
> B.hs:5:5:
>     Not in scope: data constructor ‘A1’
>     Perhaps you meant ‘A2’ (imported from A)
> }}}
>
> The issue is that the import `A(..)` brings all of `A`s data constructors
> and accessors into scope, but not any associated pattern synonyms.
> Instead I have to enable `PatternSynonyms` in module `B` (or just import
> everything from `A`).
>
> {{{#!hs
> {-# LANGUAGE PatternSynonyms #-}
> module B where
>
> import A ( A(..), pattern A1 )
>
> a = A1 0
> }}}
>
> I'd like to propose that we extend the semantics of the `A(..)`
> import/export notation to include any associated pattern synonyms. I
> think this is in line with the spirit of `PatternSynonyms`, that the
> extension should allow internal refactoring without causing API breakage,
> and that the extension should only need to be enabled to *define* pattern
> synonyms.
>
> FYI, this issue does appear in the wild, I ran into it while working on
> https://phabricator.haskell.org/D861 and had to modify two import lists
> in Cabal.

New description:

 Suppose I have the following two modules.

 {{{#!hs
 {-# LANGUAGE PatternSynonyms #-}
 module A where

 data A = A2 Int Int

 pattern A1 a <- A2 a _ where
   A1 a = A2 a 0
 }}}
 {{{#!hs
 module B where

 import A ( A(..) )

 a = A1 0
 }}}

 When I try to compile `B.hs` I get an error because `A1` is unbound in
 module `B`.

 {{{
 $ ghc --make B.hs
 [1 of 2] Compiling A                ( A.hs, A.o )
 [2 of 2] Compiling B                ( B.hs, B.o )

 B.hs:5:5:
     Not in scope: data constructor ‘A1’
     Perhaps you meant ‘A2’ (imported from A)
 }}}

 The issue is that the import `A(..)` brings all of `A`s data constructors
 and accessors into scope, but not any associated pattern synonyms. Instead
 I have to enable `PatternSynonyms` in module `B` (or just import
 everything from `A`).

 {{{#!hs
 {-# LANGUAGE PatternSynonyms #-}
 module B where

 import A ( A(..), pattern A1 )

 a = A1 0
 }}}

 I'd like to propose that we extend the semantics of the `A(..)`
 import/export notation to include any associated pattern synonyms. I think
 this is in line with the spirit of `PatternSynonyms`, that the extension
 should allow internal refactoring without causing API breakage, and that
 the extension should only need to be enabled to *define* pattern synonyms.

 FYI, this issue does appear in the wild, I ran into it while working on
 https://phabricator.haskell.org/D861 and had to modify two import lists in
 Cabal.

 There is a specification and discussion of this feature on the wiki page
 [wiki:PatternSynonyms/AssociatingSynonyms].

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10653#comment:35>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list