[GHC] #8753: Import constructor but not the data type

#8753: Import constructor but not the data type ------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- How do I import a constructor but not its data type? The constructor might have the name of a data type which I do not want to bring into scope. Use case: Library (A) defines a parametrized data type (D a) which I want to use in my code (B) in instantiated form (D Int) but with the same name (D). I want to pattern match against inhabitants of type D, so I need the constructor(s) in scope. Here is how it could look like if import lists let me specify whether I want to import a type or a constructor with name "D". module A where data D a = D a module B where import A (constructor D) import qualified A D = A.D Int f :: D -> Int f (D x) = x Haskell has different name spaces for type and constructors, but does not let the user talk about these name spaces where it matters, namely in import/export lists. At least I found no documentation instructing me how to do this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): Andreas, I think pattern synonyms cover this need. Have you tried them out yet? :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Old description:
How do I import a constructor but not its data type? The constructor might have the name of a data type which I do not want to bring into scope.
Use case: Library (A) defines a parametrized data type (D a) which I want to use in my code (B) in instantiated form (D Int) but with the same name (D). I want to pattern match against inhabitants of type D, so I need the constructor(s) in scope.
Here is how it could look like if import lists let me specify whether I want to import a type or a constructor with name "D".
module A where
data D a = D a
module B where
import A (constructor D) import qualified A D = A.D Int
f :: D -> Int f (D x) = x
Haskell has different name spaces for type and constructors, but does not let the user talk about these name spaces where it matters, namely in import/export lists. At least I found no documentation instructing me how to do this.
New description: How do I import a constructor but not its data type? The constructor might have the name of a data type which I do not want to bring into scope. Use case: Library (`A`) defines a parametrized data type (`D a`) which I want to use in my code (`B`) in instantiated form (`D Int`) but with the same name (`D`). I want to pattern match against inhabitants of type `D`, so I need the constructor(s) in scope. Here is how it could look like if import lists let me specify whether I want to import a type or a constructor with name "`D`". {{{#!haskell module A where data D a = D a }}} {{{#!haskell module B where import A (constructor D) import qualified A D = A.D Int f :: D -> Int f (D x) = x }}} Haskell has different name spaces for type and constructors, but does not let the user talk about these name spaces where it matters, namely in import/export lists. At least I found no documentation instructing me how to do this. -- Comment (by hvr): (fixed-up wiki markup in ticket description) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 andreas.abel): Indeed, they could do the job, but are they in ghc 7.6? I have not tried ghc 7.7. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * cc: cactus (added) Comment: You are right that there is no good way to do this, and that the lack is unfortunate. It is, however, possible in GHC 7.8. You can say {{{ import A( pattern D ) }}} provided you use `LANGUAGE PatternSynonyms`. Here `D` is a data constructor, but that's just a degenerate pattern synonym. Similarly in hiding and export lists. Does that help? I see that this point does not (yet) show up in the user manual, and it should. Gergo, might you fix that? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 andreas.abel): That certainly addresses the issue. No need to for a separate syntax for constructors, if it works for patterns in general. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by nomeata): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by goldfire): Is this in the manual? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Documentation | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by nomeata): * status: closed => new * resolution: fixed => * component: Compiler => Documentation * type: feature request => task Comment: Doesn’t seem like it. http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html #pattern-synonyms mentions `pattern Foo` in export/import list, but does not say that proper constructors can also be addressed this way. I guess it should also be mentioned in http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html #explicit-namespaces Anywhere else where this should be mentioned? (Reopening as a task.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Documentation | Version: 7.6.3 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 goldfire): That looks sufficient to me... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8753: Import constructor but not the data type
-------------------------------------+------------------------------------
Reporter: andreas.abel | Owner:
Type: task | Status: new
Priority: normal | Milestone:
Component: Documentation | Version: 7.6.3
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 Simon Peyton Jones

#8753: Import constructor but not the data type -------------------------------------+------------------------------------ Reporter: andreas.abel | Owner: Type: task | Status: closed Priority: normal | Milestone: Component: Documentation | Version: 7.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * status: new => closed * resolution: => fixed Comment: Good idea, done. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8753#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC