Record syntax for pattern synonyms

Richard Eisenberg eir at cis.upenn.edu
Tue Aug 11 13:11:54 UTC 2015


I think debating the overall idea before implementing is a great idea. Here's my reason why I like these: it allows a library designer to change an internal representation of a previously-concrete datatype while providing backward compatibility. Since the datatype had been exporting its constructors, clients might have used record update. Now the author can change the datatype and add pattern synonyms to keep the interface constant. Without the feature proposed here, such a change would be impossible.

Furthermore, record update syntax is awfully convenient, and may be attractive to new libraries with abstract types. I haven't tried to do it, but I imagine you could do some cool lens-like constructs with proper (ab)use of this feature.

Richard

On Aug 11, 2015, at 9:05 AM, Dr. ÉRDI Gergő <gergo at erdi.hu> wrote:

> Record field updates via patsyns looks very weird to me (and, as just a user, it would be unexpected). Can't we do just matchers and builders for now, and add field updaters as a second step, if there's concensus that it's a Good Idea?
> 
> Bye,
> Gergo
> 
> On 11 Aug 2015 07:11, "Matthew Pickering" <matthewtpickering at gmail.com> wrote:
> I was looking at implementing #8582 but before I got too far I thought
> it best to clear up a few design points.
> 
> A summary can be found below and a more fleshed out version with some
> examples can be found on the wiki page[1].
> 
> My main question is about how best to deal with record updates. Say
> that Foo is a record pattern synonym then how would we expect the
> following program to behave?
> 
> ```
> foo a at Foo{..} = a {bar = baz}
> ```
> 
> Then say that `pattern Foo{bar} = Just bar`, how should the following
> two programs behave? Is this partiality any different to that caused
> by ordinary use of pattern synonyms? (At least partiality in patterns
> is warned but how comprehensive is the coverage?)
> 
> ```
> foo :: Maybe a -> Maybe Int
> foo x = x {bar = 5}
> 
> -- error as `bar` unique determines that we need Foo
> bar = Nothing {bar = 5}
> ```
> 
> Abandoning record updates seems to make record syntax for pattern
> synonyms far less useful and confusing to users. Is this design how
> others have imagined it? I have cced Gergő who originally implemented
> the extension and created #8582.
> 
> Matt
> 
> ----
> 
> Unidirectional patterns
> * Provide the same ability to match as normal records (RecordWildcards etc)
> * Provide selector functions
> 
> Bidirectional patterns
> * Provide the constructor which can be used as normal record constructors
> 
> Record Updates - unclear
> * Generalise update syntax to arbitrary expressions?
> 
> 
> [1]: https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms#RecordPatternSynonyms
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20150811/fd0cabdb/attachment.html>


More information about the ghc-devs mailing list