category feedHow to make code warning-freeMiscellaneouseditdelete

This category is a stub, contributions are welcome!






What to do if you can't get rid of a warning

If you can't get rid of a warning, you can disable it explicitly in the module by adding a pragma. GHC prints flag names next to warnings:

lib/Fmt.hs:1189:1: warning: [-Worphans]
    Orphan instance:
      ...

So, to disable -Worphans, the pragma would have to look like this:

{-# OPTIONS_GHC -Wno-orphans #-}
edit description
or press Ctrl+Enter to savemarkdown supported
#
OverlappingInstances
other
move item up move item down edit item info delete item
Summary edit summary

Starting from GHC 7.10, instead of {-# LANGUAGE OverlappingInstances #-} you have to mark specific instances with {-# OVERLAPPABLE #-}, {-# OVERLAPPING #-} or {-# OVERLAPS #-}. So, if you want to use overlapping instances, here's how you can do it:

#if __GLASGOW_HASKELL__ < 710
{-# LANGUAGE OverlappingInstances #-}
#  define _OVERLAPPING_
#  define _OVERLAPPABLE_
#  define _OVERLAPS_
#else
#  define _OVERLAPPING_ {-# OVERLAPPING #-}
#  define _OVERLAPPABLE_ {-# OVERLAPPABLE #-}
#  define _OVERLAPS_ {-# OVERLAPS #-}
#endif

Now you can just mark your instances as instance _OVERLAPPING_ ... instead of instance {-# OVERLAPPING #-}, and it'll work without warnings on all GHC versions.

Summary quit editing summary
#
Defined but not used
other
move item up move item down edit item info delete item
Summary edit summary

Sometimes you have functions or types that you don't use anywhere in the module and don't export. In this case you will get these warnings:

test.hs:6:1-3: warning: [-Wunused-top-binds] …
    Defined but not used: ‘foo’

test.hs:11:1-14: warning: [-Wunused-top-binds] …
    Defined but not used: type constructor or class ‘Foo’

One way to silence them is to add {-# OPTIONS -Wno-unused-top-binds #-} to your module. Another is to add _ in front of all unused functions' names, like this:

_foo :: Int
_foo = 1

Unfortunately, this only works with functions and not types. Moreover, sometimes you can't modify function names as they are generated (by Template Haskell, for instance). In this case you can add a fake “usage” to the end of the file:

foo, bar :: Int
foo = 1
bar = 2
-------------------------------------
_unused :: ()
_unused = const () (foo, bar)

The same could be done for types:

type Foo = Int
type Bar = Bool
-------------------------------------
_unusedTypes :: (Foo, Bar)
_unusedTypes = undefined

(If you don't want to use undefined, you can use Proxy.)

Summary quit editing summary