Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 631
    • Merge requests 631
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #10653

PatternSynonyms should be imported/exported as part of the wildcard notation

Suppose I have the following two modules.

{-# LANGUAGE PatternSynonyms #-}
module A where

data A = A2 Int Int

pattern A1 a <- A2 a _ where
  A1 a = A2 a 0
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 As 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).

{-# 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 PatternSynonyms/AssociatingSynonyms.

Edited Mar 10, 2019 by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking