#11351 closed bug (fixed)

Scoped type variables in pattern synonyms

Reported by: Iceland_jack Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.0.1-rc1
Keywords: PatternSynonyms Cc: mpickering
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

Unsure of pattern synonym scoping rules. I want to be able to refer to a type in the signature (assuming symbol from #11349):

symbol :: forall s. KnownSymbol s => String
symbol = symbolVal @s Proxy

-- Not in scope: type variable ‘s’
-- Not in scope: type variable ‘s’
pattern Symbol :: forall s. KnownSymbol s => String
pattern Symbol <- ((== symbol @s) -> True) where
         Symbol = symbol @s

Without TypeApplications:

-- • Could not deduce (KnownSymbol n0)
--     arising from a use of ‘symbolVal’
--   from the context: KnownSymbol s
--     bound by the type signature for pattern synonym ‘Symbol’:
--                String
pattern Symbol :: forall s. KnownSymbol s => String
pattern Symbol <- ((== symbolVal (Proxy :: Proxy s)) -> True)

but it (GHCi, version 8.1.20160102) says the type variable s is not in scope. Is this intentional?

Change History (6)

comment:1 Changed 18 months ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 18 months ago by simonpj

You are right: scoped type variables from the pattern signature should scope, and they simply don't right now. That's a bug; or at least a serious inconsistency.

comment:3 Changed 18 months ago by thomie

Cc: mpickering added
Keywords: PatternSynonyms added
Type: feature requestbug
Version: 8.18.0.1-rc1

comment:4 Changed 17 months ago by Simon Peyton Jones <simonpj@…>

In e2c7b7ee/ghc:

Implement scoped type variables in pattern synonyms

This fixes Trac #11351.   The implementation is pretty
simple, happily.

I took the opportunity to re-order the prov/req context
in builder-ids, which was confusingly backwards.

comment:5 Changed 17 months ago by simonpj

Status: newmerge

I think it'd be safe to merge this.

Still missing is a refactoring of the pattern-synonym documentation.

comment:6 Changed 17 months ago by bgamari

Milestone: 8.0.1
Resolution: fixed
Status: mergeclosed

This has been merged to ghc-8.0 as 8c10ee3cacdd4f88561751e96831435397aef4e9.

Note: See TracTickets for help on using tickets.