Go to the first, previous, next, last section, table of contents.

Warnings and sanity-checking

GHC has a selection of options that select which types of non-fatal error messages, otherwise known as warnings, can be generated during compilation. By default, you get a standard set of warnings which are generally likely to indicate bugs in your program. These are: `-fwarn-overlpapping-patterns' and `-fwarn-missing-methods'. The following flags are simple ways to select standard "packages" of warnings:

`-Wnot':
Turns off all warnings, including the standard ones.
`-w':
Synonym for `-Wnot'.
`-W':
Provides the standard warnings plus `-fwarn-incomplete-patterns' and `-fwarn-unused-names'.
`-Wall':
Turns on all warning options.

The full set of warning options is described below. To turn off any warning, simply give the corresponding `-fno-warn-...' option on the command line.

`-fwarn-name-shadowing':
This option causes a warning to be emitted whenever an inner-scope value has the same name as an outer-scope value, i.e. the inner value shadows the outer one. This can catch typographical errors that turn into hard-to-find bugs, e.g., in the inadvertent cyclic definition `let x = ... x ... in'. Consequently, this option does not allow cyclic recursive definitions.
`-fwarn-overlapping-patterns':
By default, the compiler will warn you if a set of patterns are either incomplete (i.e., you're only matching on a subset of an algebraic data type's constructors), or overlapping, i.e.,
f :: String -> Int
f []     = 0
f (_:xs) = 1
f "2"    = 2

g [] = 2
where the last pattern match in `f' won't ever be reached, as the second pattern overlaps it. More often than not, redundant patterns is a programmer mistake/error, so this option is enabled by default.
`-fwarn-incomplete-patterns':
Similarly for incomplete patterns, the function `g' will fail when applied to non-empty lists, so the compiler will emit a warning about this when this option is enabled.
`-fwarn-missing-methods':
This option is on by default, and warns you whenever an instance declaration is missing one or more methods, and the corresponding class declaration has no default declaration for them.
`-fwarn-unused-names':
Have the renamer report which locally defined names are not used/exported. This option is not currently supported.
`-fwarn-duplicate-exports':
Have the compiler warn about duplicate entries in export lists. This is useful information if you maintain large export lists, and want to avoid the continued export of a definition after you've deleted (one) mention of it in the export list. This option is on by default.

If you would like GHC to check that every top-level value has a type signature, use the `-fsignatures-required' option.

If you're feeling really paranoid, the `-dcore-lint' option is a good choice. It turns on heavyweight intra-pass sanity-checking within GHC. (It checks GHC's sanity, not yours.)


Go to the first, previous, next, last section, table of contents.