Skip to content

[] interpreted as an overloaded list in rule LHS

Compiling Data.Set.Internal produces the following:

Data/Set/Internal.hs:958:11: warning: [-Winline-rule-shadowing]
    Rule "Set.toAscListBack" may never fire
      because rule "Class op fromListN" for ‘GHCExts.fromListN’ might fire first
    Probable fix: add phase [n] or [~n] to the competing rule
    |
958 | {-# RULES "Set.toAscListBack" [1] foldrFB (:) [] = toAscList #-}
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Data/Set/Internal.hs:960:11: warning: [-Winline-rule-shadowing]
    Rule "Set.toDescListBack" may never fire
      because rule "Class op fromListN" for ‘GHCExts.fromListN’ might fire first
    Probable fix: add phase [n] or [~n] to the competing rule
    |
960 | {-# RULES "Set.toDescListBack" [1] foldlFB (\xs x -> x : xs) [] = toDescList #-}
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As mpickering figured out, the trouble is that [] in the rule LHS is being interpreted as an overloaded list. The module does not enable OverloadedLists. Furthermore, even if it did, I would argue that it is never correct to put one in a rule LHS, so we should always interpret [] as the empty list constructor in RULES left-hand sides.

Edited by David Feuer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information