Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#12366 closed feature request (invalid)

Use TypeOperators for pattern synonyms?

Reported by: dubiousjim Owned by:
Priority: low Milestone:
Component: Compiler (Parser) Version: 8.0.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

With the language setting -XTypeOperators, I can use varsym expressions, like <|, as type constructors. I would expect that we would then also be able to use them as pattern synonyms; but we can't. This is a request for that to become possible.

{-# LANGUAGE TypeOperators, PatternSynonyms #-}

module Main where

pattern (<|) x xs = Just (x, xs)

main = case Just (1, [2,3]) of { Nothing -> putStrLn "Nothing"; y <| ys -> print y }

gives a parse error.

Change History (3)

comment:1 Changed 12 months ago by goldfire

Unfortunately, I don't think this is possible. The type-level namespace and the term-level namespace are organized differently: |> in a type is indeed like a capitalized word, but |> in a term is like a lowercase word. The problem is, as I understand it, that the parser needs to be able to know where the constructors/pattern synonyms are in a pattern. Is C (|>) binding the variable |> or are we matching against a nullary pattern synonym |>? It's impossible to tell.

comment:2 Changed 12 months ago by mpickering

Keywords: PatternSynonyms added
Resolution: invalid
Status: newclosed

Pattern synonym names live in the data constructor name space whilst the type operators extension only affects type constructors. Pattern synonym definitions define no type construction so there shouldn't be any interaction between the two features.

comment:3 Changed 12 months ago by dubiousjim

Ok, thanks for the prompt and clear explanation.

Note: See TracTickets for help on using tickets.