Unused type variables with non-linear patterns

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

Unused type variables with non-linear patterns

Jan Stolarek
An intersting thing came up when implementing warnings for unused type variables in type family
patterns (#10982 / D1576):

type family X a b where
  X a a = Int

Should we emit a warning that `a` is unused? It does not appear in the RHS but it is actually used
because of non-linear pattern. We can fix this by prefixing both appearances of `a` with an
underscore - this silences the warning and maintains semantics. Nevertheless, if a variable is
unused it should be perfectly valid to replace it with an underscore - that is not the case in
this example. Thoughts?

Janek

---
Politechnika Łódzka
Lodz University of Technology

Treść tej wiadomości zawiera informacje przeznaczone tylko dla adresata.
Jeżeli nie jesteście Państwo jej adresatem, bądź otrzymaliście ją przez pomyłkę
prosimy o powiadomienie o tym nadawcy oraz trwałe jej usunięcie.

This email contains information intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient or if you have received this message in error,
please notify the sender and delete it from your system.
_______________________________________________
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: Unused type variables with non-linear patterns

Michael Sloan
I definitely think this should be considered a usage.  Ideally, you should always be able to resolve warnings, but there'd be no straightforward way to do so if LHS-only usages cause warnings.  Also, It's quite useful to use type variables only on the LHS.  Usage example: https://hackage.haskell.org/package/base-4.8.1.0/docs/src/Data.Type.Equality.html#EqStar

-Michael

On Thu, Dec 10, 2015 at 6:48 AM, Jan Stolarek <[hidden email]> wrote:
An intersting thing came up when implementing warnings for unused type variables in type family
patterns (#10982 / D1576):

type family X a b where
  X a a = Int

Should we emit a warning that `a` is unused? It does not appear in the RHS but it is actually used
because of non-linear pattern. We can fix this by prefixing both appearances of `a` with an
underscore - this silences the warning and maintains semantics. Nevertheless, if a variable is
unused it should be perfectly valid to replace it with an underscore - that is not the case in
this example. Thoughts?

Janek

---
Politechnika Łódzka
Lodz University of Technology

Treść tej wiadomości zawiera informacje przeznaczone tylko dla adresata.
Jeżeli nie jesteście Państwo jej adresatem, bądź otrzymaliście ją przez pomyłkę
prosimy o powiadomienie o tym nadawcy oraz trwałe jej usunięcie.

This email contains information intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient or if you have received this message in error,
please notify the sender and delete it from your system.
_______________________________________________
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: Unused type variables with non-linear patterns

Richard Eisenberg-2
I agree with Michael. This should not emit a warning.

While you're in this area, make sure that

> type instance F _ _ = Int

indeed matches `F Char Bool`. It's easy to imagine both underscores being treated as the same variable, which is not what the user intends.

Thanks,
Richard

On Dec 10, 2015, at 4:32 PM, Michael Sloan <[hidden email]> wrote:

I definitely think this should be considered a usage.  Ideally, you should always be able to resolve warnings, but there'd be no straightforward way to do so if LHS-only usages cause warnings.  Also, It's quite useful to use type variables only on the LHS.  Usage example: https://hackage.haskell.org/package/base-4.8.1.0/docs/src/Data.Type.Equality.html#EqStar

-Michael

On Thu, Dec 10, 2015 at 6:48 AM, Jan Stolarek <[hidden email]> wrote:
An intersting thing came up when implementing warnings for unused type variables in type family
patterns (#10982 / D1576):

type family X a b where
  X a a = Int

Should we emit a warning that `a` is unused? It does not appear in the RHS but it is actually used
because of non-linear pattern. We can fix this by prefixing both appearances of `a` with an
underscore - this silences the warning and maintains semantics. Nevertheless, if a variable is
unused it should be perfectly valid to replace it with an underscore - that is not the case in
this example. Thoughts?

Janek

---
Politechnika Łódzka
Lodz University of Technology

Treść tej wiadomości zawiera informacje przeznaczone tylko dla adresata.
Jeżeli nie jesteście Państwo jej adresatem, bądź otrzymaliście ją przez pomyłkę
prosimy o powiadomienie o tym nadawcy oraz trwałe jej usunięcie.

This email contains information intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient or if you have received this message in error,
please notify the sender and delete it from your system.
_______________________________________________
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


_______________________________________________
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: Unused type variables with non-linear patterns

Simon Peyton Jones

I agree too.

 

Is there a ticket?   Does it emit a warning right now?

 

Simon

 

From: ghc-devs [mailto:[hidden email]] On Behalf Of Richard Eisenberg
Sent: 11 December 2015 16:02
To: Michael Sloan <[hidden email]>
Cc: [hidden email]
Subject: Re: Unused type variables with non-linear patterns

 

I agree with Michael. This should not emit a warning.

 

While you're in this area, make sure that

 

> type instance F _ _ = Int

 

indeed matches `F Char Bool`. It's easy to imagine both underscores being treated as the same variable, which is not what the user intends.

 

Thanks,

Richard

 

On Dec 10, 2015, at 4:32 PM, Michael Sloan <[hidden email]> wrote:



I definitely think this should be considered a usage.  Ideally, you should always be able to resolve warnings, but there'd be no straightforward way to do so if LHS-only usages cause warnings.  Also, It's quite useful to use type variables only on the LHS.  Usage example: https://hackage.haskell.org/package/base-4.8.1.0/docs/src/Data.Type.Equality.html#EqStar

 

-Michael

 

On Thu, Dec 10, 2015 at 6:48 AM, Jan Stolarek <[hidden email]> wrote:

An intersting thing came up when implementing warnings for unused type variables in type family
patterns (#10982 / D1576):

type family X a b where
  X a a = Int

Should we emit a warning that `a` is unused? It does not appear in the RHS but it is actually used
because of non-linear pattern. We can fix this by prefixing both appearances of `a` with an
underscore - this silences the warning and maintains semantics. Nevertheless, if a variable is
unused it should be perfectly valid to replace it with an underscore - that is not the case in
this example. Thoughts?

Janek

---
Politechnika Łódzka
Lodz University of Technology

Treść tej wiadomości zawiera informacje przeznaczone tylko dla adresata.
Jeżeli nie jesteście Państwo jej adresatem, bądź otrzymaliście ją przez pomyłkę
prosimy o powiadomienie o tym nadawcy oraz trwałe jej usunięcie.

This email contains information intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient or if you have received this message in error,
please notify the sender and delete it from your system.
_______________________________________________
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

 


_______________________________________________
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: Unused type variables with non-linear patterns

Jan Stolarek
> Is there a ticket?
#10982

Janek

---
Politechnika Łódzka
Lodz University of Technology

Treść tej wiadomości zawiera informacje przeznaczone tylko dla adresata.
Jeżeli nie jesteście Państwo jej adresatem, bądź otrzymaliście ją przez pomyłkę
prosimy o powiadomienie o tym nadawcy oraz trwałe jej usunięcie.

This email contains information intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient or if you have received this message in error,
please notify the sender and delete it from your system.
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs