Implementing pattern synonym constructor signatures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing pattern synonym constructor signatures

David Feuer-2
Over the past week I've started digging into the code that implements pattern synonyms with an eye toward implementing the pattern synonym construction function signature proposal. I think I understand a decent amount of what's going on most places. However, I don't understand enough about type checking to have any idea about what needs to change where or how. There are several things that need to be addressed:

0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?

1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?

2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.

3. A pattern synonym without a constructor signature needs to be treated as it is today, so the machinery for matching things up needs to remain available.

David Feuer
Well-Typed, LLP

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Implementing pattern synonym constructor signatures

Matthew Pickering
What is a constructor signature? Where is this specified?

On Mon, Jan 15, 2018 at 7:10 PM, David Feuer <[hidden email]> wrote:

> Over the past week I've started digging into the code that implements
> pattern synonyms with an eye toward implementing the pattern synonym
> construction function signature proposal. I think I understand a decent
> amount of what's going on most places. However, I don't understand enough
> about type checking to have any idea about what needs to change where or
> how. There are several things that need to be addressed:
>
> 0. Parsing. I wasn't actually able to find the code that parses pattern
> synonyms. Can someone point me in the right direction?
>
> 1. When there is a constructor signature, it needs to be used for the
> construction function instead of the pattern signature. Can someone give
> point me in the right direction about how to do this?
>
> 2. When there is a constructor signature but no pattern signature, what
> should we do? I think "give up" sounds okay for now.
>
> 3. A pattern synonym without a constructor signature needs to be treated as
> it is today, so the machinery for matching things up needs to remain
> available.
>
> David Feuer
> Well-Typed, LLP
>
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Implementing pattern synonym constructor signatures

David Feuer-2
See the accepted proposal:  https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0005-bidir-constr-sigs.rst



David Feuer
Well-Typed, LLP

-------- Original message --------
From: Matthew Pickering <[hidden email]>
Date: 1/15/18 3:27 PM (GMT-05:00)
To: David Feuer <[hidden email]>
Cc: Simon Peyton Jones <[hidden email]>, GHC developers <[hidden email]>
Subject: Re: Implementing pattern synonym constructor signatures

What is a constructor signature? Where is this specified?

On Mon, Jan 15, 2018 at 7:10 PM, David Feuer <[hidden email]> wrote:

> Over the past week I've started digging into the code that implements
> pattern synonyms with an eye toward implementing the pattern synonym
> construction function signature proposal. I think I understand a decent
> amount of what's going on most places. However, I don't understand enough
> about type checking to have any idea about what needs to change where or
> how. There are several things that need to be addressed:
>
> 0. Parsing. I wasn't actually able to find the code that parses pattern
> synonyms. Can someone point me in the right direction?
>
> 1. When there is a constructor signature, it needs to be used for the
> construction function instead of the pattern signature. Can someone give
> point me in the right direction about how to do this?
>
> 2. When there is a constructor signature but no pattern signature, what
> should we do? I think "give up" sounds okay for now.
>
> 3. A pattern synonym without a constructor signature needs to be treated as
> it is today, so the machinery for matching things up needs to remain
> available.
>
> David Feuer
> Well-Typed, LLP
>
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: Implementing pattern synonym constructor signatures

GHC - devs mailing list
In reply to this post by David Feuer-2

0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?

 

Parser.y line 1356, production ‘patteron_synonym_decl’ looks plausible.

 

Currently we have

data HsPatSynDir id

  = Unidirectional

  | ImplicitBidirectional

  | ExplicitBidirectional (MatchGroup id (LHsExpr id))

so in the bidirectional case all we have a MatchGroup, built with mkPatSynMatchGroup.    To serve the proposal we need an optional signature in there too.

 

1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?

 

TcPatSyn.tcPatSynBuilderBind is a good place to start.

 

2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.

 

I don’t understand.  Can you give an example?

 

Simon

From: David Feuer [mailto:[hidden email]]
Sent: 15 January 2018 19:11
To: Simon Peyton Jones <[hidden email]>
Cc: [hidden email]
Subject: Implementing pattern synonym constructor signatures

 

Over the past week I've started digging into the code that implements pattern synonyms with an eye toward implementing the pattern synonym construction function signature proposal. I think I understand a decent amount of what's going on most places. However, I don't understand enough about type checking to have any idea about what needs to change where or how. There are several things that need to be addressed:

 

0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?

 

1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?

 

2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.

 

3. A pattern synonym without a constructor signature needs to be treated as it is today, so the machinery for matching things up needs to remain available.

 

David Feuer

Well-Typed, LLP


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Implementing pattern synonym constructor signatures

David Feuer-2
In reply to this post by David Feuer-2
Never mind about parsing. It looks like the parser is already doing what it needs to do and I need to look to RdrHsSyn.hs.



David Feuer
Well-Typed, LLP

-------- Original message --------
From: David Feuer <[hidden email]>
Date: 1/15/18 2:10 PM (GMT-05:00)
To: Simon Peyton Jones <[hidden email]>
Subject: Implementing pattern synonym constructor signatures

Over the past week I've started digging into the code that implements pattern synonyms with an eye toward implementing the pattern synonym construction function signature proposal. I think I understand a decent amount of what's going on most places. However, I don't understand enough about type checking to have any idea about what needs to change where or how. There are several things that need to be addressed:
0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?
1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?
2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.
3. A pattern synonym without a constructor signature needs to be treated as it is today, so the machinery for matching things up needs to remain available.
David FeuerWell-Typed, LLP
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: Implementing pattern synonym constructor signatures

David Feuer-2
In reply to this post by GHC - devs mailing list
3. Someone could write

pattern P x <- ... where
  P :: ...
  P x = ...

The pattern signature has to be the same as the constructor signature except for constraints, so it doesn't necessarily sound trivial to infer.



David Feuer
Well-Typed, LLP

-------- Original message --------
From: Simon Peyton Jones <[hidden email]>
Date: 1/15/18 6:36 PM (GMT-05:00)
To: David Feuer <[hidden email]>
Subject: RE: Implementing pattern synonym constructor signatures

0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?

Parser.y line 1356, production ‘patteron_synonym_decl’ looks plausible.

Currently we have
data HsPatSynDir id
  = Unidirectional
  | ImplicitBidirectional
  | ExplicitBidirectional (MatchGroup id (LHsExpr id))
so in the bidirectional case all we have a MatchGroup, built with mkPatSynMatchGroup.    To serve the proposal we need an optional signature in there too.

1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?

TcPatSyn.tcPatSynBuilderBind is a good place to start.

2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.

I don’t understand.  Can you give an example?

Simon
From: David Feuer [mailto:[hidden email]]
Sent: 15 January 2018 19:11
To: Simon Peyton Jones <[hidden email]>
Cc: [hidden email]
Subject: Implementing pattern synonym constructor signatures

Over the past week I've started digging into the code that implements pattern synonyms with an eye toward implementing the pattern synonym construction function signature proposal. I think I understand a decent amount of what's going on most places. However, I don't understand enough about type checking to have any idea about what needs to change where or how. There are several things that need to be addressed:

0. Parsing. I wasn't actually able to find the code that parses pattern synonyms. Can someone point me in the right direction?

1. When there is a constructor signature, it needs to be used for the construction function instead of the pattern signature. Can someone give point me in the right direction about how to do this?

2. When there is a constructor signature but no pattern signature, what should we do? I think "give up" sounds okay for now.

3. A pattern synonym without a constructor signature needs to be treated as it is today, so the machinery for matching things up needs to remain available.

David Feuer
Well-Typed, LLP

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs