[GHC] #11959: Importing doubly exported pattern synonym and associated pattern synonym panics

GHC ghc-devs at haskell.org
Thu Sep 15 23:53:05 UTC 2016


#11959: Importing doubly exported pattern synonym and associated pattern synonym
panics
-------------------------------------+-------------------------------------
        Reporter:  darchon           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  8.0.2
       Component:  Compiler          |              Version:  8.0.1-rc3
      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):  Phab:D2132,
       Wiki Page:                    |  Phab:D2133
-------------------------------------+-------------------------------------

Comment (by bgamari):

 On Phab:D2133 Simon said (paraphrasing),

 > Consider these two export lists
 > a. {{{module M( Vec2( Nil, Cons ) ) where ...}}}
 >
 > b. {{{module M( Vec2( Nil, Cons ), pattern Cons ) where ...}}}
 > {{{
 > These should generate precisely the same .hi file, but they don't. They
 look like
 > a. {{{
 >    exports:
 >      Vec2{Cons Nil}
 >    }}}
 > b. {{{
 >    exports:
 >      Cons
 >      Vec2{Cons Nil}
 >    }}}

 It's not entirely clear to me that this is true. Consider these two export
 lists,

 1. {{{module M( Vec2( Nil, Cons ) ) where ...}}}

 2. {{{module M( Vec2, pattern Nil, pattern Cons ) where ...}}}

 These two mean quite different things for the end-user when they go to
 import this module.
 Namely, they will need to use, respectively,
 1. {{{import M(Vec2(Cons))}}}
 2. {{{import M(Cons)}}}
 Note that the user cannot import the definitions from export list (1) with
 import list (2) and vice versa.

 This means that if the user gives us export list (b) from above and we map
 it
 to the same exports as produced by export list (a), we have made a non-
 obvious
 decision for the user, who now cannot use import list (2) to import `Cons`
 from
 `M`. It is possible we have even acted against `M`'s author's will, which
 was
 to allow both import lists.


 While we're discussing this, I'd also point out that there is a bit of
 inconsistency in how we treat bundled things. Consider,
 {{{#!hs
 module AModule ( ARecord(..) ) where
 data ARecord = ARec { hello :: Int }
 }}}
 In this case one could use either
 {{{#!hs
 import AModule (hello)  -- or...
 import AModule (ARecord(hello))
 }}}
 to import `hello` (although the `ARec` constructor must be imported in
 "bundled" style). While this makes some amount of sense (since selectors
 can be easily thought of as either free-floating functions or parts of
 data), it does make me wonder whether we should be equally liberal in the
 case of patterns.

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


More information about the ghc-tickets mailing list