[GHC] #11164: No way to import a data instance

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs import Foreign.R.Type as R (SComplex) }}} results in {{{ In module ‘Foreign.R.Type’: ‘SComplex’ is a data constructor of ‘Sing’ To import it use ‘import’ Foreign.R.Type( Sing( SComplex ) ) or ‘import’ Foreign.R.Type( Sing(..) ) }}} But if I try the suggested {{{#!hs import Foreign.R.Type as R (Sing(SComplex)) }}} I get {{{ Module ‘Foreign.R.Type’ does not export ‘Sing(SComplex)’ }}} So, when a module defines a data instance but does not export the family, there appears to be no way to bring that instance in scope (short of importing the whole module). Here's the module itself http://haddock.stackage.org/nightly-2015-10-19/inline-r-0.7.1.2/Foreign-R-Ty.... It doesn't have an explicit export list; that's how it manages to export instances without the family itself. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: 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 goldfire): Does {{{#!hs import Foreign.R.Type as R ( pattern SComplex ) }}} work? If it doesn't, it should. The `pattern` keyword in import/export lists has been extended to apply to ordinary data constructors. These should include data family instance constructors, too. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: 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 Feuerbach): Turns out it does, but that's hardly a proper solution: 1. It is very confusing for someone reading the code and not obvious for the one writing it 2. It requires -XPatternSynonyms 3. That's not what ghc suggests -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: 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 goldfire): Agreed on all fronts. Would it be better to have this rule? * Whenever a module omits an export list, if that module declares and data instances, the data family is also (re-)exported. That would seem to fix your problem. Note that there is no difficulty if the exporting module specifies an export list, as it has to either export the data family itself, or use `pattern` to export the data instance constructor. In the latter case, we assume the module author has a reason not to export the data family (and, the exact same scenario happens with ordinary datatypes, requiring importers with import lists to also use `pattern`). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: 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):
Would it be better to have this rule? * Whenever a module omits an export list, if that module declares and data instances, the data family is also (re-)exported.
Yes I agree with this. Would someone like to execute? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by kanetw): * owner: => kanetw -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Changes (by kanetw): * status: new => patch * differential: => phab:D1573 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Comment (by kanetw): Small note: this test has slightly weird output: {{{ --- ./ghci/scripts/T5417.stdout.normalised 2015-12-05 12:03:09.099962730 +0100 +++ ./ghci/scripts/T5417.run.stdout.normalised 2015-12-05 12:03:09.099962730 +0100 @@ -3,5 +3,7 @@ data family D a class C.C1 a where data family C.F a +class C.C1 a where + data family C.F a -- Defined at T5417a.hs:5:5 data instance C.F (B1 a) = B2 a -- Defined at T5417.hs:8:10 }}} but looking at what the individual script command outputs I actually like the output more: {{{ *T5417> :browse data B1 a = B1 a data instance C.F (B1 a) = B2 a data family D a class C.C1 a where data family C.F a *T5417> :info C.F class C.C1 a where data family C.F a -- Defined at T5417a.hs:5:5 data instance C.F (B1 a) = B2 a -- Defined at T5417.hs:8:10 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance
-------------------------------------+-------------------------------------
Reporter: Feuerbach | Owner: kanetw
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): phab:D1573
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * owner: kanetw => * status: closed => new * resolution: fixed => Comment: Wait a sec. [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/type- families.html#data-family-import-export Section 7.7.4 of the user manual] describes how the rules for exports are modified for families; so it definitely needs a new bullet! And the adjustment in `exports_from_avail` is delicate. It actually only fires on data families, because only with data families can we have a ''locally-defined'' subordinate thing (data constructor, class op) whose parent type constructor is ''imported''. Worth spelling this out. All this only applies for modules with no export list. The comment says "Generally, whenever we export a part of a declaration, export the declaration, too." That seems a bit misleading, doesn't it? It really only applies to data families. So I'm ok with the code but I do think the documentation needs a little work (comments, user manual). Many thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Changes (by kanetw): * owner: => kanetw Comment: The export list syntax itself stays unmodified and I adjusted the example 'That (annoyingly) means that you cannot selectively import Y selectively, thus "import Y( D(D1,D2) )", because Y does not export D.' already. See the `docs/users_guide/glasgow_exts.rst` diff in Phab. I'll edit the comment. I was trying to phrase what I was doing in a general way but I got a bit too general. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I know that the syntax remains unchanged. But the semantics does not. And the opening section of 7.7.4 is all about semantics. There are four bullets at the moment and we need a fifth. An example illustrates, but this is the specification! Thanks Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573, Wiki Page: | phab:D1587 -------------------------------------+------------------------------------- Changes (by kanetw): * status: new => patch * differential: phab:D1573 => phab:D1573, phab:D1587 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11164: No way to import a data instance
-------------------------------------+-------------------------------------
Reporter: Feuerbach | Owner: kanetw
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): phab:D1573,
Wiki Page: | phab:D1587
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#11164: No way to import a data instance -------------------------------------+------------------------------------- Reporter: Feuerbach | Owner: kanetw Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | rename/should_compile/T11164 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): phab:D1573, Wiki Page: | phab:D1587 -------------------------------------+------------------------------------- Changes (by thomie): * testcase: => rename/should_compile/T11164 * status: patch => closed * resolution: => fixed * milestone: => 8.0.1 Comment: KaneTW wrote the patch and the documentation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11164#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC