Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,351
    • Issues 5,351
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 573
    • Merge requests 573
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • 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
  • #9953
Closed
Open
Issue created Jan 02, 2015 by Simon Peyton Jones@simonpjDeveloper

Pattern synonyms don't work with GADTs

Consider this variant of test T8968-1:

{-# LANGUAGE GADTs, KindSignatures, PatternSynonyms #-}
module ShouldCompile where

data X :: * -> * where
  Y :: a -> X (Maybe a)

pattern C :: a -> X (Maybe a)
pattern C x = Y x

foo :: X t -> t
foo (C x) = Just x
  • If we had (Y x) instead of (C x) in the LHS of foo, then this is an ordinary GADT program and typechecks fine.
  • If we omit the pattern signature, it typechecks fine, and :info C says
pattern C :: t ~ Maybe a => a -> X t 	-- Defined in ‘ShouldCompile’
  • But as written, it fails with
Foo.hs:11:6:
    Couldn't match type ‘t’ with ‘Maybe a0’
      ‘t’ is a rigid type variable bound by
          the type signature for: foo :: X t -> t at Foo.hs:10:8
    Expected type: X t
      Actual type: X (Maybe a0)
    Relevant bindings include foo :: X t -> t (bound at Foo.hs:11:1)
    In the pattern: C x
    In an equation for ‘foo’: foo (C x) = Just x

Moreover, :info C says

pattern C :: a -> X (Maybe a) 	-- Defined at Foo.hs:8:9

Do you see the difference? In the former, the "prov_theta" equality constraint is explicit, but in the latter it's implicit.

The exact thing happens for DataCons. It's handled via the dcEqSpec field. Essentially PatSyn should have a new field for the implicit equality constraints. And, just as for data consructors, we need to generate the equality constraints, and the existentials that are needed, when we process the signature. Use the code in TcTyClsDecls.rejigConRes (perhaps needs a better name).

This is all pretty serious. Without fixing it, GADT-style pattern signatures are all but useless.

Trac metadata
Trac field Value
Version 7.8.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking