Skip to content

Pattern synonyms are highlighted as definitions #1313

Closed
@taktoa

Description

@taktoa

It seems to me that every instance of the token pattern in the attached code sample should be highlighted with the keyword face (i.e.: the same face as module, class, where, etc.).

The main objection to this kind of fix is that people could want to name a function pattern when the extension is disabled. However, the proc keyword has similar problems but is currently being syntax-highlighted regardless of the presence of the relevant language pragma. I guess proc is technically in the Haskell 2010 Report so it's Official Haskell whereas -XPatternSynonyms is merely GHC Haskell, but I think that doesn't hold much water given the popularity of GHC extensions.

{-# LANGUAGE GADTs           #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE UnicodeSyntax   #-}
{-# LANGUAGE ViewPatterns    #-}

-- Pattern synonyms can be exported
module Main (pattern A1) where

data Foo = Foo
data Bar where Bar :: (Show a) => a -> Bar

-- Basic usage of unidirectional and bidirectional pattern synonyms
pattern A1 <- Foo
pattern A2 = Foo

-- Patterns can have type signatures
-- These type signatures have up to two contexts
-- (these are called CProv and CReq for proven and required constraints resp.)
pattern B1 :: (Show a) => (Show a) => a -> Bar
pattern B1 x <- Bar x
pattern B2 :: (Show a) => (Show a) => a -> Bar
pattern B2 x =  Bar x

-- If CProv is empty, it can be omitted.
pattern C1 :: (Show a) => a -> Bar
pattern C1 x <- Bar x
pattern C2 :: (Show a) => a -> Bar
pattern C2 x =  Bar x

-- If CProv is not empty but CReq is, it's denoted like so:
pattern D1 :: (Show a) => () => a -> Bar
pattern D1 x <- Bar x
pattern D2 :: (Show a) => () => a -> Bar
pattern D2 x =  Bar x

-- Explicitly-bidirectional pattern synonym
pattern Succ n <- (subtract 1 -> n) where Succ n = n + 1

-- With -XUnicodeSyntax, ← can be used for a unidirectional synonym definition
pattern Baz  Foo

-- For comparison, a function definition:
foo :: Int -> Int
foo x = x + 5

main :: IO ()
main = return ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions