Concrete syntax for pattern synonym type signatures

Simon Peyton Jones simonpj at microsoft.com
Sun Nov 9 19:11:32 UTC 2014


On this thread:

* I'm strongly of the opinion that pattern signatures should start
	pattern P :: ...blah...

  Just like value signatures, the pattern name comes first,
  then a double colon. 

* I really don't like syntax that puts the
  pattern name in the middle.

* It's vital that a GADT constructor should have a signature just
  like a GADT constructor.

* I'm not wedded to ";". I chose it just because it seemed like a 
  grouping operator that binds less tightly than ",".

  A vertical bar would be fine with me.  But:
  I'm a little worried that "(|" is a useful bracketing lexeme,
  already used for arrow syntax, so you might have to put a space
  between the paren and the bar.

* One other possibility would be two => thus
	pattern P :: (Eq b) => (Num a, Eq a) => ...blha...

  If you wanted something which had a "match-required" part but no
  "match-provided" part, you'd end up with
	patter P :: () => (Num a, Eq a) => ...blah...
  which is a little odd, but perhaps no odder than
	pattern P :: ( | Num a, Eq a ) => ...blah...

  This has the considerable merit of requiring no new syntax at all.
  There is the difficulty of remembering which way round the match-required
  and match-provided stuff is, but all versions have that problem.

* We don't need to disturb the syntax for HsType; we can just have
  a parser for this particular form; in effect a modified HsForAll,
  just for pattern type signatures, and probably flattened out into
  the pattern-signature constructor form itself.

Does that help?

Simon

| -----Original Message-----
| From: Dr. ERDI Gergo [mailto:gergo at erdi.hu]
| Sent: 09 November 2014 07:56
| To: Simon Peyton Jones
| Cc: GHC Devs
| Subject: RE: Concrete syntax for pattern synonym type signatures
| 
| On Tue, 4 Nov 2014, Simon Peyton Jones wrote:
| 
| >  pattern P :: forall tvs. (match-provided ; match-required) => tau
| >
| > The "; match-required" part is optional, and the "match-provided" part
| might be empty.  So P1 and P2 would look like this:
| >
| >  pattern P1 :: forall a. (; Num a) => b -> (a,b)
| >  pattern P2 :: forall a. (; Num a, Ord a) => a -> a
| 
| Doesn't the ';' look a bit like something that could be incidentially
| introduced by some layout-aware syntax rule? Wouldn't, e.g., '|' be more
| explicit as a separator?
| 
| example:
| 
| pattern P :: forall tvs. (Eq b | Num a, Eq a) => b -> T a



More information about the ghc-devs mailing list