Opened 21 months ago

Last modified 9 days ago

#8582 new feature request

Record syntax for pattern synonyms

Reported by: cactus Owned by: mpickering
Priority: high Milestone: 7.12.1
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: Phab:D1152


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 (7)

comment:1 Changed 14 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 6 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 6 months ago by blamario (previous) (diff)

comment:3 Changed 3 months ago by cactus

  • Keywords PatternSynonyms added

comment:4 Changed 2 months ago by mpickering

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

comment:5 Changed 4 weeks ago by mpickering

  • Owner changed from cactus to mpickering

comment:6 Changed 3 weeks ago by mpickering

  • Differential Revisions set to Phab:D1152

comment:7 Changed 9 days ago by simonpj

  • Milestone set to 7.12.1
  • Priority changed from normal to high

Matthew says he thinks this'll be ready for 7.12 so I'll milestone it as such.

Note: See TracTickets for help on using tickets.