Changes between Version 10 and Version 11 of Design/LocalWarningPragmas


Ignore:
Timestamp:
Dec 4, 2015 12:43:11 PM (4 years ago)
Author:
edgar.zhavoronkov
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Design/LocalWarningPragmas

    v10 v11  
    2020It is not very easy to form a good use case for this but nevertheless.
    2121
    22 1. For example, if you depend on particular library function(if you want to support backward compatability) but in newer version of library this function marked as deprecated and so you get warnings about it. Here it may be useful to suppress them instead of rewriting the whole codebase.
     221. For example, if you depend on particular library function(if you want to support backward compatability) but in newer version of library this function marked as deprecated and so you get warnings about it. Here it may be useful to suppress them instead of rewriting the whole codebase. I have asked about use cases on [https://www.reddit.com/r/haskell/comments/3rbpb6/examples_of_warnings_in_haskell/ Haskell's reddit cahnnel] 
    23232. Recent monad of no return proposal suggests that having `Applicative` context sufficed for `Monad` assumes that `return` is already implemented as `pure`, so we don't need to duplicate code. However, Monad still has minimal complete definition `>>=` and `return`, so we can have warnings about incomplete minimal definition.
    2424
     
    3838
    3939bar :: a -> b -> c
    40 {-# SUPPRESS foo #-}
     40{-# SUPPRESS bar #-}
    4141bar x y = foo y $ x
    4242}}}
    4343
    44 We are suppressing warnings for one particular function
     44We are suppressing warnings for one particular function. By writing `{-# SUPPRESS bar #-}` i mean that all warnings that function `bar` throws will be suppressed.
     45
     46Another example:
    4547
    4648{{{#!hs
    47 {-# SUPPRESS return #-}
    48 instance Applicative m => Monad m where
    49     (>>=) = ...
     49
     50module Test where
     51
     52{-# SUPPRESS foo #-}
     53foo :: Integer -> Integer
     54foo n | n >= 0 = fac n
     55      | n < 0 = n + 1
     56        where
     57            fac x | x == 0 = 1
     58                  | x /= 0 = x * fac (x - 1)
     59foo _ = undefined
    5060
    5161}}}
    52 And here we are suppressing warnings about incomplete minimal
    5362
     63With -Wall GHC will warn us about incomplete pattern matching for `fac` however, `fac` is used and defined only when `n >= 0`. So we write `{-# SUPPRESS foo #-}` and this warning(and others that `foo` throws) will be suppressed and not printed to user.
     64