Typing pattern synonyms

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

Typing pattern synonyms

Sven Panne-2
The type of a pattern synonym like

   pattern FOO = 1234

seems to be '(Eq a, Num a) => a', which makes partially makes sense, although it's not immediately clear to me where the 'Eq a' part comes from. But probably that would be clear if I read the desugaring rules closely enough. ;-) My real question is about:

   pattern FOO = 1234 :: Int

This doesn't compile out of the box, GHC seems to require ScopedTypeVariables, too:

    Illegal type signature: `Int'
      Perhaps you intended to use ScopedTypeVariables
    In a pattern type-signature

Why is this the case? From a user perspective, the error is totally bogus, there are no visible type variables at all. Can GHC be fixed to avoid enabling ScopedTypeVariables?

Cheers,
   S.


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

Re: Typing pattern synonyms

David Feuer

The Eq constraint is needed to support pattern matching, the raison d’être of pattern synonyms. I'm pretty sure the reason you need ScopedTypeVariables for your second example is that GHC only allows pattern signatures with that extension enabled. Once upon a time there was a separate PatternSignatures extension, I believe, but not any more.

On Sep 30, 2015 2:04 PM, "Sven Panne" <[hidden email]> wrote:
The type of a pattern synonym like

   pattern FOO = 1234

seems to be '(Eq a, Num a) => a', which makes partially makes sense, although it's not immediately clear to me where the 'Eq a' part comes from. But probably that would be clear if I read the desugaring rules closely enough. ;-) My real question is about:

   pattern FOO = 1234 :: Int

This doesn't compile out of the box, GHC seems to require ScopedTypeVariables, too:

    Illegal type signature: `Int'
      Perhaps you intended to use ScopedTypeVariables
    In a pattern type-signature

Why is this the case? From a user perspective, the error is totally bogus, there are no visible type variables at all. Can GHC be fixed to avoid enabling ScopedTypeVariables?

Cheers,
   S.


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


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

Re: Typing pattern synonyms

Bardur Arantsson-2
On 09/30/2015 08:10 PM, David Feuer wrote:
> The Eq constraint is needed to support pattern matching, the raison d’être
> of pattern synonyms. I'm pretty sure the reason you need
> ScopedTypeVariables for your second example is that GHC only allows pattern
> signatures with that extension enabled. Once upon a time there was a
> separate PatternSignatures extension, I believe, but not any more.

Perhaps ScopedTypeVariables by default (or only?) would be relevant for
the revamped[1] Haskell' committee?

Would there be any actual downsides? It's always seemed to me that
ScopedTypeVariables was the way it should have been from the start
(given perfect foresight).

Regards,

[1] http://permalink.gmane.org/gmane.comp.lang.haskell.prime/3965

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

Re: Typing pattern synonyms

David Feuer

Edward Kmett seems to have some concerns about its implications for type checker implementations. Personally, I have little interest in programming in a Haskell that doesn't have a feature with the power to express what ScopedTypeVariables can. That said, there are some weird corners in the design relating to pattern signatures and in particular to pattern bindings.

On Sep 30, 2015 2:26 PM, "Bardur Arantsson" <[hidden email]> wrote:
On 09/30/2015 08:10 PM, David Feuer wrote:
> The Eq constraint is needed to support pattern matching, the raison d’être
> of pattern synonyms. I'm pretty sure the reason you need
> ScopedTypeVariables for your second example is that GHC only allows pattern
> signatures with that extension enabled. Once upon a time there was a
> separate PatternSignatures extension, I believe, but not any more.

Perhaps ScopedTypeVariables by default (or only?) would be relevant for
the revamped[1] Haskell' committee?

Would there be any actual downsides? It's always seemed to me that
ScopedTypeVariables was the way it should have been from the start
(given perfect foresight).

Regards,

[1] http://permalink.gmane.org/gmane.comp.lang.haskell.prime/3965

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

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

Re: Typing pattern synonyms

Sven Panne-2
In reply to this post by David Feuer
2015-09-30 20:10 GMT+02:00 David Feuer <[hidden email]>:

The Eq constraint is needed to support pattern matching, the raison d’être of pattern synonyms.

I was just a bit confused by the fact that normally you don't need an 'Eq a' constraint for pattern matching. But looking at the Haskell report, one can see that matching against numeric/char/string literals involves (==), so:

    \x -> case x of 1234 -> undefined :: (Eq a, Num a) => a -> r

This makes sense now, and there is no magic involved. :-]

I'm pretty sure the reason you need ScopedTypeVariables for your second example is that GHC only allows pattern signatures with that extension enabled.

My main question is: Why is this the case? Is it really necessary in our simple example? The GHC docs should probably mention the magic behind this in the patter synonym section.
 

Once upon a time there was a separate PatternSignatures extension, I believe, but not any more.

Never heard of that one...

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users