Opened 17 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: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: #5144 Blocking:
Related Tickets: Differential Revisions:

Description

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

comment:1 Changed 9 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 4 weeks ago by blamario

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

data Foo = Foo{bar :: String}

to

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

Edit:

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 weeks ago by blamario (previous) (diff)
Note: See TracTickets for help on using tickets.