Constructor as outermost match in RULE under GHC 8.2.2 & 8.4.3

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

Constructor as outermost match in RULE under GHC 8.2.2 & 8.4.3

Conal Elliott
GHC 8.2.2 and 8.4.3 dislike the following rules:

``` haskell
{-# RULES

"pair fst snd" forall p. (,) (exl p) (exr p) = p

"swap" forall p. (,) (exr p) (exl p) = swap p

 #-}
```

Error messages:

``` haskell
/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:485:1: warning:
    A constructor, (,), appears as outermost match in RULE lhs.
    This rule will be ignored.
    |
485 | "pair fst snd" forall p. (,) (exl p) (exr p) = p
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:489:1: warning:
    A constructor, (,), appears as outermost match in RULE lhs.
    This rule will be ignored.
    |
489 | "swap" forall p. (,) (exr p) (exl p) = swap p
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

GHC 8.0.2 didn't complain about these rules, though I'm unsure whether they worked as desired.

Why disallow such rules (with constructors at the head)?

-- Conal


_______________________________________________
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: Constructor as outermost match in RULE under GHC 8.2.2 & 8.4.3

Ben Gamari-2
On August 2, 2018 9:25:05 PM EDT, Conal Elliott <[hidden email]> wrote:

>GHC 8.2.2 and 8.4.3 dislike the following rules:
>
>``` haskell
>{-# RULES
>
>"pair fst snd" forall p. (,) (exl p) (exr p) = p
>
>"swap" forall p. (,) (exr p) (exl p) = swap p
>
> #-}
>```
>
>Error messages:
>
>``` haskell
>/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:485:1: warning:
>    A constructor, (,), appears as outermost match in RULE lhs.
>    This rule will be ignored.
>    |
>485 | "pair fst snd" forall p. (,) (exl p) (exr p) = p
>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:489:1: warning:
>    A constructor, (,), appears as outermost match in RULE lhs.
>    This rule will be ignored.
>    |
>489 | "swap" forall p. (,) (exr p) (exl p) = swap p
>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>```
>
>GHC 8.0.2 didn't complain about these rules, though I'm unsure whether
>they
>worked as desired.
>
>Why disallow such rules (with constructors at the head)?
>
>-- Conal

While we only started warning about them recently, previously the rules almost certainly weren't firing as you expected them to. The trouble is that constructors are often replaced with their wrappers rather early in simplification. This meant that matching on constructors in rules was quite unreliable. This is discussed in #13290.

Cheers,

- Ben
_______________________________________________
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: Constructor as outermost match in RULE under GHC 8.2.2 & 8.4.3

Conal Elliott
I get it. Thanks, Ben!

On Fri, Aug 3, 2018 at 12:48 PM, Ben Gamari <[hidden email]> wrote:
On August 2, 2018 9:25:05 PM EDT, Conal Elliott <[hidden email]> wrote:
>GHC 8.2.2 and 8.4.3 dislike the following rules:
>
>``` haskell
>{-# RULES
>
>"pair fst snd" forall p. (,) (exl p) (exr p) = p
>
>"swap" forall p. (,) (exr p) (exl p) = swap p
>
> #-}
>```
>
>Error messages:
>
>``` haskell
>/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:485:1: warning:
>    A constructor, (,), appears as outermost match in RULE lhs.
>    This rule will be ignored.
>    |
>485 | "pair fst snd" forall p. (,) (exl p) (exr p) = p
>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>/Users/conal/Haskell/concat/plugin/src/ConCat/Rebox.hs:489:1: warning:
>    A constructor, (,), appears as outermost match in RULE lhs.
>    This rule will be ignored.
>    |
>489 | "swap" forall p. (,) (exr p) (exl p) = swap p
>    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>```
>
>GHC 8.0.2 didn't complain about these rules, though I'm unsure whether
>they
>worked as desired.
>
>Why disallow such rules (with constructors at the head)?
>
>-- Conal

While we only started warning about them recently, previously the rules almost certainly weren't firing as you expected them to. The trouble is that constructors are often replaced with their wrappers rather early in simplification. This meant that matching on constructors in rules was quite unreliable. This is discussed in #13290.

Cheers,

- Ben


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