diff options
author | Max Bolingbroke <batterseapower@hotmail.com> | 2009-07-01 20:03:44 +0000 |
---|---|---|
committer | Max Bolingbroke <batterseapower@hotmail.com> | 2009-07-01 20:03:44 +0000 |
commit | 9d0c8f842e35dde3d570580cf62a32779f66a6de (patch) | |
tree | dbe3743f4ff24c8d4ed7129c780b179275e3748e /docs | |
parent | ab1d5052de53479377c961d1e966f0cf0b82c592 (diff) | |
download | haskell-9d0c8f842e35dde3d570580cf62a32779f66a6de.tar.gz |
Support for -fwarn-unused-do-bind and -fwarn-wrong-do-bind, as per #3263
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/flags.xml | 14 | ||||
-rw-r--r-- | docs/users_guide/using.xml | 56 |
2 files changed, 68 insertions, 2 deletions
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index 978ddf7464..f96edbfada 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -1175,6 +1175,20 @@ <entry><option>-fno-warn-unused-matches</option></entry> </row> + <row> + <entry><option>-fwarn-unused-do-bind</option></entry> + <entry>warn about do bindings that appear to throw away values of types other than <literal>()</literal></entry> + <entry>dynamic</entry> + <entry><option>-fno-warn-unused-do-bind</option></entry> + </row> + + <row> + <entry><option>-fwarn-wrong-do-bind</option></entry> + <entry>warn about do bindings that appear to throw away monadic values that you should have bound instead</entry> + <entry>dynamic</entry> + <entry><option>-fno-warn-wrong-do-bind</option></entry> + </row> + </tbody> </tgroup> </informaltable> diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml index 478a6bc20e..024a4e7869 100644 --- a/docs/users_guide/using.xml +++ b/docs/users_guide/using.xml @@ -845,7 +845,8 @@ ghc -c Foo.hs</screen> <option>-fwarn-duplicate-exports</option>, <option>-fwarn-missing-fields</option>, <option>-fwarn-missing-methods</option>, - <option>-fwarn-lazy-unlifted-bindings</option>, and + <option>-fwarn-lazy-unlifted-bindings</option>, + <option>-fwarn-wrong-do-bind</option>, and <option>-fwarn-dodgy-foreign-imports</option>. The following flags are simple ways to select standard “packages” of warnings: @@ -877,7 +878,8 @@ ghc -c Foo.hs</screen> <option>-fwarn-simple-patterns</option>, <option>-fwarn-tabs</option>, <option>-fwarn-incomplete-record-updates</option>, - <option>-fwarn-monomorphism-restriction</option>, and + <option>-fwarn-monomorphism-restriction</option>, + <option>-fwarn-unused-do-bind</option>, and <option>-fwarn-implicit-prelude</option>.</para> </listitem> </varlistentry> @@ -1365,6 +1367,56 @@ f "2" = 2 </listitem> </varlistentry> + <varlistentry> + <term><option>-fwarn-unused-do-bind</option>:</term> + <listitem> + <indexterm><primary><option>-fwarn-unused-do-bind</option></primary></indexterm> + <indexterm><primary>unused do binding, warning</primary></indexterm> + <indexterm><primary>do binding, unused</primary></indexterm> + + <para>Report expressions occuring in <literal>do</literal> and <literal>mdo</literal> blocks + that appear to silently throw information away. + For instance <literal>do { mapM popInt xs ; return 10 }</literal> would report + the first statement in the <literal>do</literal> block as suspicious, + as it has the type <literal>StackM [Int]</literal> and not <literal>StackM ()</literal>, but that + <literal>[Int]</literal> value is not bound to anything. The warning is suppressed by + explicitly mentioning in the source code that your program is throwing something away: + <programlisting> + do { _ <- mapM popInt xs ; return 10 } + </programlisting> + Of course, in this particular situation you can do even better: + <programlisting> + do { mapM_ popInt xs ; return 10 } + </programlisting> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-fwarn-wrong-do-bind</option>:</term> + <listitem> + <indexterm><primary><option>-fwarn-wrong-do-bind</option></primary></indexterm> + <indexterm><primary>apparently erroneous do binding, warning</primary></indexterm> + <indexterm><primary>do binding, apparently erroneous</primary></indexterm> + + <para>Report expressions occuring in <literal>do</literal> and <literal>mdo</literal> blocks + that appear to lack a binding. + For instance <literal>do { return (popInt 10) ; return 10 }</literal> would report + the first statement in the <literal>do</literal> block as suspicious, + as it has the type <literal>StackM (StackM Int)</literal> (which consists of two nested applications + of the same monad constructor), but which is not then "unpacked" by binding the result. + The warning is suppressed by explicitly mentioning in the source code that your program is throwing something away: + <programlisting> + do { _ <- return (popInt 10) ; return 10 } + </programlisting> + For almost all sensible programs this will indicate a bug, and you probably intended to write: + <programlisting> + do { popInt 10 ; return 10 } + </programlisting> + </para> + </listitem> + </varlistentry> + </variablelist> <para>If you're feeling really paranoid, the |