Preparing for a review of pattern synonyms

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Dr. ERDI Gergo
Hi,

I believe I've finished implementing version 1 of pattern synonyms (i.e.
everything described in #5144, minus the things in #8581, #8582, #8583 and
#8584). I've discussed the way forward with SPJ and he suggested because
of the cross-cutting nature of the patch, I should wait a reasonably long
time (~1 month) after 7.8 is branched off for things to settle, and
then formally submit it for review.

So my question is, is there anything I can do in the meantime, in
preparation for the review? The code is available at
https://github.com/gergoerdi/ghc. I've also added some tests
to the testsuite (https://github.com/gergoerdi/ghc-testsuite), and
updated the wiki pages at
https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms and
https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/Implementation.

Thanks,
  Gergo


Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Gabor Greif-2
On 12/9/13, Dr. ERDI Gergo <gergo at erdi.hu> wrote:
> Hi,

Hi Gerg?,

>
> I believe I've finished implementing version 1 of pattern synonyms (i.e.
> everything described in #5144, minus the things in #8581, #8582, #8583 and
> #8584). I've discussed the way forward with SPJ and he suggested because
> of the cross-cutting nature of the patch, I should wait a reasonably long
> time (~1 month) after 7.8 is branched off for things to settle, and
> then formally submit it for review.

Geat to hear this.

>
> So my question is, is there anything I can do in the meantime, in
> preparation for the review? The code is available at

Does your implementation cover only H98 ADTs or do you support
existentials/GADTs too?

Cheers,

    Gabor

> https://github.com/gergoerdi/ghc. I've also added some tests
> to the testsuite (https://github.com/gergoerdi/ghc-testsuite), and
> updated the wiki pages at
> https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms and
> https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/Implementation.
>
> Thanks,
>   Gergo
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Peyton Jones
In reply to this post by Dr. ERDI Gergo
Just to say that I'm very pleased by this work.  Haskell can abstract over just about everything except patterns, and this feature fixes that embarrassing lack.  I've discussed the implementation extensively with Gergo, and he's more-or-less rewritten it several times. It's quite pretty I think.  

Thanks too to Lennart for pressing for it.  I believe the first impetus came at the Cambridge Haskell Hackathon.

Simon

| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Dr.
| ERDI Gergo
| Sent: 09 December 2013 06:06
| To: GHC Devs
| Subject: Preparing for a review of pattern synonyms
|
| Hi,
|
| I believe I've finished implementing version 1 of pattern synonyms (i.e.
| everything described in #5144, minus the things in #8581, #8582, #8583
| and
| #8584). I've discussed the way forward with SPJ and he suggested because
| of the cross-cutting nature of the patch, I should wait a reasonably
| long
| time (~1 month) after 7.8 is branched off for things to settle, and
| then formally submit it for review.
|
| So my question is, is there anything I can do in the meantime, in
| preparation for the review? The code is available at
| https://github.com/gergoerdi/ghc. I've also added some tests
| to the testsuite (https://github.com/gergoerdi/ghc-testsuite), and
| updated the wiki pages at
| https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms and
| https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/Implementation.
|
| Thanks,
|   Gergo
|
| _______________________________________________
| ghc-devs mailing list
| ghc-devs at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-devs

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Peyton Jones
In reply to this post by Dr. ERDI Gergo
PS: it was so obvious that I forgot to add: a major thank-you to Gergo, who did ALL the work.

Simon

| -----Original Message-----
| From: Simon Peyton-Jones
| Sent: 09 December 2013 08:58
| To: 'Dr. ERDI Gergo'; GHC Devs
| Cc: Augustsson, Lennart
| Subject: RE: Preparing for a review of pattern synonyms
|
| Just to say that I'm very pleased by this work.  Haskell can abstract
| over just about everything except patterns, and this feature fixes that
| embarrassing lack.  I've discussed the implementation extensively with
| Gergo, and he's more-or-less rewritten it several times. It's quite
| pretty I think.
|
| Thanks too to Lennart for pressing for it.  I believe the first impetus
| came at the Cambridge Haskell Hackathon.
|
| Simon
|
| | -----Original Message-----
| | From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Dr.
| | ERDI Gergo
| | Sent: 09 December 2013 06:06
| | To: GHC Devs
| | Subject: Preparing for a review of pattern synonyms
| |
| | Hi,
| |
| | I believe I've finished implementing version 1 of pattern synonyms
| (i.e.
| | everything described in #5144, minus the things in #8581, #8582, #8583
| | and
| | #8584). I've discussed the way forward with SPJ and he suggested
| because
| | of the cross-cutting nature of the patch, I should wait a reasonably
| | long
| | time (~1 month) after 7.8 is branched off for things to settle, and
| | then formally submit it for review.
| |
| | So my question is, is there anything I can do in the meantime, in
| | preparation for the review? The code is available at
| | https://github.com/gergoerdi/ghc. I've also added some tests
| | to the testsuite (https://github.com/gergoerdi/ghc-testsuite), and
| | updated the wiki pages at
| | https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms and
| | https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/Implementation.
| |
| | Thanks,
| |   Gergo
| |
| | _______________________________________________
| | ghc-devs mailing list
| | ghc-devs at haskell.org
| | http://www.haskell.org/mailman/listinfo/ghc-devs

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Marlow-7
I think pattern synonyms are great!  A couple of questions:

  * what will Haddock show for a pattern export?

  * can we still write pattern matches that GHC can infer
    to be exhaustive when using pattern synonyms?

Are we not doing ViewPatternsAlternative any more?
https://ghc.haskell.org/trac/ghc/wiki/ViewPatternsAlternative
Or is that just being treated as an orthogonal issue?  I rather like
that proposal, and we originally discussed it in conjunction with
pattern synonyms.

Cheers,
Simon

On 09/12/2013 08:58, Simon Peyton-Jones wrote:

> PS: it was so obvious that I forgot to add: a major thank-you to Gergo, who did ALL the work.
>
> Simon
>
> | -----Original Message-----
> | From: Simon Peyton-Jones
> | Sent: 09 December 2013 08:58
> | To: 'Dr. ERDI Gergo'; GHC Devs
> | Cc: Augustsson, Lennart
> | Subject: RE: Preparing for a review of pattern synonyms
> |
> | Just to say that I'm very pleased by this work.  Haskell can abstract
> | over just about everything except patterns, and this feature fixes that
> | embarrassing lack.  I've discussed the implementation extensively with
> | Gergo, and he's more-or-less rewritten it several times. It's quite
> | pretty I think.
> |
> | Thanks too to Lennart for pressing for it.  I believe the first impetus
> | came at the Cambridge Haskell Hackathon.
> |
> | Simon
> |
> | | -----Original Message-----
> | | From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Dr.
> | | ERDI Gergo
> | | Sent: 09 December 2013 06:06
> | | To: GHC Devs
> | | Subject: Preparing for a review of pattern synonyms
> | |
> | | Hi,
> | |
> | | I believe I've finished implementing version 1 of pattern synonyms
> | (i.e.
> | | everything described in #5144, minus the things in #8581, #8582, #8583
> | | and
> | | #8584). I've discussed the way forward with SPJ and he suggested
> | because
> | | of the cross-cutting nature of the patch, I should wait a reasonably
> | | long
> | | time (~1 month) after 7.8 is branched off for things to settle, and
> | | then formally submit it for review.
> | |
> | | So my question is, is there anything I can do in the meantime, in
> | | preparation for the review? The code is available at
> | | https://github.com/gergoerdi/ghc. I've also added some tests
> | | to the testsuite (https://github.com/gergoerdi/ghc-testsuite), and
> | | updated the wiki pages at
> | | https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms and
> | | https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/Implementation.
> | |
> | | Thanks,
> | |   Gergo
> | |
> | | _______________________________________________
> | | ghc-devs mailing list
> | | ghc-devs at haskell.org
> | | http://www.haskell.org/mailman/listinfo/ghc-devs
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Dr. ERDI Gergo
In reply to this post by Gabor Greif-2
On Mon, 9 Dec 2013, Gabor Greif wrote:

>> So my question is, is there anything I can do in the meantime, in
>> preparation for the review? The code is available at
>
> Does your implementation cover only H98 ADTs or do you support
> existentials/GADTs too?

Yes, it has full support for GHC's type system extensions.

--

   .--= ULLA! =-----------------.
    \     http://gergo.erdi.hu   \
     `---= gergo at erdi.hu =-------'
If I drive fast enough at the red light, it'll appear green.

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Dr. ERDI Gergo
In reply to this post by Simon Marlow-7
Hi Simon,

On Mon, 9 Dec 2013, Simon Marlow wrote:

> I think pattern synonyms are great!  A couple of questions:
>
> * what will Haddock show for a pattern export?

Is Haddock a part of GHC? I don't know. If it's not, then whatever parser
it's using will have to be extended to support pattern synonyms.

> * can we still write pattern matches that GHC can infer
>   to be exhaustive when using pattern synonyms?

No. I don't see how that would be possible without having access to the
pattern synonym definition when typechecking/compiling a use site. One
deliberate design decision was to make pattern synonyms proper
abstractions, in the sense that compiling use sites shouldn't require
access to its definition details.

> Are we not doing ViewPatternsAlternative any more?
> https://ghc.haskell.org/trac/ghc/wiki/ViewPatternsAlternative
> Or is that just being treated as an orthogonal issue?  I rather like that
> proposal, and we originally discussed it in conjunction with pattern
> synonyms.

It should be treated as orthogonal -- if and when GHC gets support for it,
they will be available in PatternSynonyms as well.

If there's no separate Trac ticket for ViewPatternsAlternative yet, I'm
happy
to open one.

Bye,
  Gergo

--

   .--= ULLA! =-----------------.
    \     http://gergo.erdi.hu   \
     `---= gergo at erdi.hu =-------'
I'm sure the pension plan includes all the starvation I can eat.

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Marlow-7
On 09/12/2013 13:31, Dr. ERDI Gergo wrote:

> Hi Simon,
>
> On Mon, 9 Dec 2013, Simon Marlow wrote:
>
>> I think pattern synonyms are great!  A couple of questions:
>>
>> * what will Haddock show for a pattern export?
>
> Is Haddock a part of GHC? I don't know. If it's not, then whatever
> parser it's using will have to be extended to support pattern synonyms.

Haddock uses GHC's parser, but it will need to be taught about pattern
synonyms and how to render them in documentation.

>> * can we still write pattern matches that GHC can infer
>>   to be exhaustive when using pattern synonyms?
>
> No. I don't see how that would be possible without having access to the
> pattern synonym definition when typechecking/compiling a use site. One
> deliberate design decision was to make pattern synonyms proper
> abstractions, in the sense that compiling use sites shouldn't require
> access to its definition details.

Right, I'm not suggesting that we should break the abstraction, but I
think it would be really nice if there was a way to say "the following 3
patterns are exhaustive", perhaps in a pragma.

One of the things that we ought to be able to do with this extension is
to provide abstract datatypes with pattern matching support.  The only
thing missing is support for exhaustive pattern matches.  F# active
patterns has it!

>> Are we not doing ViewPatternsAlternative any more?
>> https://ghc.haskell.org/trac/ghc/wiki/ViewPatternsAlternative
>> Or is that just being treated as an orthogonal issue?  I rather like
>> that proposal, and we originally discussed it in conjunction with
>> pattern synonyms.
>
> It should be treated as orthogonal -- if and when GHC gets support for
> it, they will be available in PatternSynonyms as well.
>
> If there's no separate Trac ticket for ViewPatternsAlternative yet, I'm
> happy to open one.

That would be great!

Cheers,
        Simon


Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Peyton Jones
| > Is Haddock a part of GHC? I don't know. If it's not, then whatever
| > parser it's using will have to be extended to support pattern
| synonyms.
|
| Haddock uses GHC's parser, but it will need to be taught about pattern
| synonyms and how to render them in documentation.

Yes, it's in utils/haddock in the main tree, and that really does need to be done before release.

| One of the things that we ought to be able to do with this extension is
| to provide abstract datatypes with pattern matching support.  The only
| thing missing is support for exhaustive pattern matches.  F# active
| patterns has it!

We already lack exhaustiveness support as soon as we have guards or view patterns.  But it seems a bit more feasible with pattern synonyms. Something to add to the "missing features" list!

Simon
 

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Dr. ERDI Gergo
In reply to this post by Simon Marlow-7
On Mon, 9 Dec 2013, Simon Marlow wrote:

>> Is Haddock a part of GHC? I don't know. If it's not, then whatever
>> parser it's using will have to be extended to support pattern synonyms.
>
> Haddock uses GHC's parser, but it will need to be taught about pattern
> synonyms and how to render them in documentation.

OK, I'll add pattern synonym support for Haddock. We don't really have a
surface syntax for pattern types (yet?), so for now I'll just use this
format:

pattern P :: b -> a -> T a; requires (Num a); provides (Eq b)

> Right, I'm not suggesting that we should break the abstraction, but I think
> it would be really nice if there was a way to say "the following 3 patterns
> are exhaustive", perhaps in a pragma.
>
> One of the things that we ought to be able to do with this extension is to
> provide abstract datatypes with pattern matching support.  The only thing
> missing is support for exhaustive pattern matches.  F# active patterns has
> it!

This should be something orthogonal to pattern synonyms that supports
regular view patterns as well.

>> If there's no separate Trac ticket for ViewPatternsAlternative yet, I'm
>> happy to open one.
>
> That would be great!

I've added it as #8605.

Bye,
  Gergo

--

   .--= ULLA! =-----------------.
    \     http://gergo.erdi.hu   \
     `---= gergo at erdi.hu =-------'
?lni tudn?k egy Nobel-b?ked?j?rt.

Reply | Threaded
Open this post in threaded view
|

Building Haddock in GHC source tree (Re: Preparing for a review of pattern synonyms)

Dr. ERDI Gergo
On Tue, 10 Dec 2013, Dr. ERDI Gergo wrote:

> OK, I'll add pattern synonym support for Haddock.

Ummm..., so how do I build the version of Haddock included in the GHC
source tree under utils? I tried just

$ cd utils/haddock
$ make

but that fails with

===--- building final phase
make -r --no-print-directory -f ghc.mk phase=final all_utils/haddock
make[2]: *** No rule to make target `all_utils/haddock'.  Stop.
make[1]: *** [all_utils/haddock] Error 2
make[1]: Leaving directory `/home/cactus/prog/haskell/ghc/ghc'


Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Simon Marlow-7
In reply to this post by Dr. ERDI Gergo
On 10/12/2013 12:11, Dr. ERDI Gergo wrote:

> On Mon, 9 Dec 2013, Simon Marlow wrote:
>
>>> Is Haddock a part of GHC? I don't know. If it's not, then whatever
>>> parser it's using will have to be extended to support pattern synonyms.
>>
>> Haddock uses GHC's parser, but it will need to be taught about pattern
>> synonyms and how to render them in documentation.
>
> OK, I'll add pattern synonym support for Haddock. We don't really have a
> surface syntax for pattern types (yet?), so for now I'll just use this
> format:
>
> pattern P :: b -> a -> T a; requires (Num a); provides (Eq b)
>
>> Right, I'm not suggesting that we should break the abstraction, but I
>> think it would be really nice if there was a way to say "the following
>> 3 patterns are exhaustive", perhaps in a pragma.
>>
>> One of the things that we ought to be able to do with this extension
>> is to provide abstract datatypes with pattern matching support.  The
>> only thing missing is support for exhaustive pattern matches.  F#
>> active patterns has it!
>
> This should be something orthogonal to pattern synonyms that supports
> regular view patterns as well.

I disagree - dealing with this in the context of pattern synonyms is
much easier.  You just need some way to declare a set of pattern synonym
constructors that together constitute an exhaustive set.  There's no
good way to "name" a view pattern for this purpose.

<perhaps slightly controversial>
Besides, I think that once pattern synonyms are in, the main use case
for view patterns will be in defining interesting pattern synonyms.  And
I'd rather use ViewPatternsAlternative for that purpose, because it's a
more natural generalisation of pattern guards.
</perhaps slightly controversial>

Cheers,
Simon

Reply | Threaded
Open this post in threaded view
|

Building Haddock in GHC source tree (Re: Preparing for a review of pattern synonyms)

Simon Marlow-7
In reply to this post by Dr. ERDI Gergo
Do you have HADDOCK_DOCS = NO in your mk/build.mk?

On 10/12/2013 14:24, Dr. ERDI Gergo wrote:

> On Tue, 10 Dec 2013, Dr. ERDI Gergo wrote:
>
>> OK, I'll add pattern synonym support for Haddock.
>
> Ummm..., so how do I build the version of Haddock included in the GHC
> source tree under utils? I tried just
>
> $ cd utils/haddock
> $ make
>
> but that fails with
>
> ===--- building final phase
> make -r --no-print-directory -f ghc.mk phase=final all_utils/haddock
> make[2]: *** No rule to make target `all_utils/haddock'.  Stop.
> make[1]: *** [all_utils/haddock] Error 2
> make[1]: Leaving directory `/home/cactus/prog/haskell/ghc/ghc'
>

Reply | Threaded
Open this post in threaded view
|

Building Haddock in GHC source tree (Re: Preparing for a review of pattern synonyms)

Herbert Valerio Riedel-3
In reply to this post by Dr. ERDI Gergo
On 2013-12-10 at 15:24:33 +0100, Dr. ERDI Gergo wrote:
> On Tue, 10 Dec 2013, Dr. ERDI Gergo wrote:
>
>> OK, I'll add pattern synonym support for Haddock.
>
> Ummm..., so how do I build the version of Haddock included in the GHC
> source tree under utils? I tried just

> $ cd utils/haddock
> $ make
>
> but that fails with

...do you have "HADDOCK_DOCS=YES" active in your mk/build.mk ?

Reply | Threaded
Open this post in threaded view
|

Building Haddock in GHC source tree (Re: Preparing for a review of pattern synonyms)

Dr. ERDI Gergo
In reply to this post by Simon Marlow-7
On Tue, 10 Dec 2013, Simon Marlow wrote:

> Do you have HADDOCK_DOCS = NO in your mk/build.mk?

yes; I thought that only controls whether documentation gets generated or
not. I've now changed it to YES and Haddock is building.

Thanks,
  Gergo

Reply | Threaded
Open this post in threaded view
|

Preparing for a review of pattern synonyms

Dr. ERDI Gergo
In reply to this post by Simon Marlow-7
On Mon, 9 Dec 2013, Simon Marlow wrote:

> I think pattern synonyms are great!  A couple of questions:
>
> * what will Haddock show for a pattern export?

I eventually ended up implementing the following syntax for Haddock
output (code is at https://github.com/gergoerdi/ghc-haddock):

     pattern (Prov b) => P a b :: (Req a) => T a

e.g.
     pattern a :< (Seq a) :: Seq a
for
     pattern x :< xs <- (Seq.viewl -> x Seq.:< xs)

or
     pattern Zero :: (Num a, Eq a) => a
for
     pattern Zero = 0

Bye,
  Gergo