Opened 20 months ago

Last modified 4 weeks ago

#8582 new feature request

Record syntax for pattern synonyms

Reported by: cactus Owned by: cactus
Priority: normal Milestone:
Component: Compiler Version:
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: #5144 Blocking:
Related Tickets: Differential Revisions:


Implement syntax for

pattern Cons{car, cdr} = (car, cdr)

which can then be used just like a regular record constructor, so the following are all valid patterns:

Cons (Just x) []
Cons{car = Just x}

Change History (4)

comment:1 Changed 13 months ago by cactus

Now that I am parsing pattern synonym declarations using the pattern parser (using the same trick as used by the data constructor parser), and typechecking a pattern synonym can add deferred bindings, this should at least be somewhat simpler to implement.

comment:2 Changed 5 months ago by blamario

I just ran into this issue. I'm trying to generalize a legacy record type like

data Foo = Foo{bar :: String}


data GenFoo s = GenFoo{bar :: s}

Unfortunately there is no way to provide a backward-compatible interface after this change. I'm hoping with this feature the solution might be as simple as

type Foo = GenFoo String
pattern Foo{bar} = GenFoo bar


Never mind, I have found a different solution:

data GenFoo s = Foo{bar :: s}

with an added compatibility module:

module Compat (Foo, GenFoo(..), module GenModule) where
import GenModule
type Foo = GenFoo String

This wasn't obvious, but it appears to work.

Last edited 4 months ago by blamario (previous) (diff)

comment:3 Changed 7 weeks ago by cactus

  • Keywords PatternSynonyms added

comment:4 Changed 4 weeks ago by mpickering

I was also thinking this would be nice and would be interested to implement it before 7.12.

Note: See TracTickets for help on using tickets.