[Haskell-cafe] Enable -Wall by default?

Viktor Dukhovni ietf-dane at dukhovni.org
Thu Dec 10 05:16:41 UTC 2020


On Wed, Dec 09, 2020 at 09:23:34PM -0500, David Feuer wrote:

> Yeah, I think you're missing something. -Wall is great for checking code
> that's supposed to be "production ready", but it makes some pretty annoying
> noise when you're deep in development. Probably the most annoying in that
> context are unused binding warnings (yeah, I'm not using it yet because I'm
> still writing it and/or other helpers), unused variable warnings (yeah,
> that'll be used in some case I still need to write), and unused imports
> (yeah, I've temporarily commented out the code that uses Foo, and I'm
> pretty sure I'll be needing Bar before I'm done). In that setting, I'm much
> more likely to want -Wincomplete-patterns (what do I still need to write)
> and maybe -Wname-shadowing (so I won't have to go back and change a bunch
> of names later) than full -Wall.

But since the proposal is about *defaults*, and a hypothetical
*default* "-Wall" can be explicitly disabled:

    $ ghci -Wall
    λ> foo :: Bool -> Int ; foo True = 1

    <interactive>:1:22: warning: [-Wincomplete-patterns]
        Pattern match(es) are non-exhaustive
        In an equation for ‘foo’: Patterns not matched: False
    λ>
    Leaving GHCi.

    ---

    $ ghci -Wall -Wno-all
    λ> foo :: Bool -> Int ; foo True = 1
    λ>
    Leaving GHCi.

the objections you raised don't necessarily rule the proposed default,
one would just need choose to use "-Wno-all" initially, and then later
turn it off.  

A more serious compatibility break would perhaps happen when one
specifies "-Werror", perhaps in combination with specific warnings to
enforce:

    $ ghci -Wall -Werror -Wno-all
    λ> 1 + 2
    3
    λ> foo :: Bool -> Int ; foo True = 1
    λ>
    Leaving GHCi.

    ---

    $ ghci -Wall -Werror
    λ> foo :: Bool -> Int ; foo True = 1

    <interactive>:1:22: error: [-Wincomplete-patterns, -Werror=incomplete-patterns]
        Pattern match(es) are non-exhaustive
        In an equation for ‘foo’: Patterns not matched: False
    λ> 1 + 2

    <interactive>:2:1: error: [-Wtype-defaults, -Werror=type-defaults]
        • Defaulting the following constraints to type ‘Integer’
            (Show a0) arising from a use of ‘print’ at <interactive>:2:1-5
            (Num a0) arising from a use of ‘it’ at <interactive>:2:1-5
        • In a stmt of an interactive GHCi command: print it
    λ>
    Leaving GHCi.

Here, adding an implicit "-Wall" stops code from compiling.  So
backwards-compatible behaviour might require "-Wall" to be explicit when
"-Werror" is specified.

Since my examples are using "ghci", I should note that for me, in
"ghci", I typically want no warnings, and "-Wall" would be a bit
of a nuisance.  But I can always alias (bash):
    
    ghci() { command ghci -v0 -Wno-all "$@"; }

And then no longer see the mostly pedantic "defaulting" warnings, or
whatever else gets in the way of quickly syntax-checking or evaluating
an expression.

-- 
    Viktor.


More information about the Haskell-Cafe mailing list