<div dir="ltr">It might be enough to just add a NOWARN <warning type> pragma that acts on a single line/expression. I've seen it in both C++ and Python linters and it works reasonably well and it's quite general.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 6, 2015 at 10:44 AM, Ben Gamari <span dir="ltr"><<a href="mailto:ben@smart-cactus.org" target="_blank">ben@smart-cactus.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sven Panne <<a href="mailto:svenpanne@gmail.com">svenpanne@gmail.com</a>> writes:<br>
<br>
> 2015-10-05 17:09 GMT+02:00 Gershom B <<a href="mailto:gershomb@gmail.com">gershomb@gmail.com</a>>:<br>
><br>
>> On October 5, 2015 at 10:59:35 AM, Bryan O'Sullivan (<a href="mailto:bos@serpentine.com">bos@serpentine.com</a>)<br>
>> wrote:<br>
>> [...] As for libraries, it has been pointed out, I believe, that without<br>
>> CPP one can write instances compatible with AMP, and also with AMP + MRP.<br>
>> One can also write code, sans CPP, compatible with pre- and post- AMP. [...]<br>
>><br>
><br>
> Nope, at least not if you care about -Wall: If you take e.g. (<$>) which is<br>
> now part of the Prelude, you can't simply import some compatibility module,<br>
> because GHC might tell you (rightfully) that that import is redundant,<br>
> because (<$>) is already visible through the Prelude. So you'll have to use<br>
> CPP to avoid that import on base >= 4.8, be it from it Data.Functor,<br>
> Control.Applicative or some compat-* module. And you'll have to use CPP in<br>
> each and every module using <$> then, unless I miss something obvious.<br>
> AFAICT all transitioning guides ignore -Wall and friends...<br>
><br>
This is a fair point that comes up fairly often. The fact that CPP is<br>
required to silence redundant import warnings is quite unfortunate.<br>
Others languages have better stories in this area. One example is Rust,<br>
which has a quite flexible `#[allow(...)]` pragma which can be used to<br>
acknowledge and silence a wide variety of warnings and lints [1].<br>
<br>
I can think of a few ways (some better than others) how we might<br>
introduce a similar idea for import redundancy checks in Haskell,<br>
<br>
 1. Attach a `{-# ALLOW redundant_import #-}` pragma to a definition,<br>
<br>
        -- in Control.Applicative<br>
        {-# ALLOW redundant_import (<$>) #-}<br>
        (<$>) :: (a -> b) -> f a -> f b<br>
        (<$>) = fmap<br>
<br>
    asking the compiler to pretend that any import of the symbol did not<br>
    exist when looking for redundant imports. This would allow library<br>
    authors to appropriately mark definitions when they are moved,<br>
    saving downstream users from having to make any change whatsoever.<br>
<br>
 2. Or alternatively we could make this a idea a bit more precise,<br>
<br>
        -- in Control.Applicative<br>
        {-# ALLOW redundant_import Prelude.(<$>) #-}<br>
        (<$>) :: (a -> b) -> f a -> f b<br>
        (<$>) = fmap<br>
<br>
    Which would ignore imports of `Control.Applicative.(<$>)` only if<br>
    `Prelude.(<$>)` were also in scope.<br>
<br>
 3. Attach a `{-# ALLOW redundancy_import #-}` pragma to an import,<br>
<br>
        import {-# ALLOW redundant_import #-} Control.Applicative<br>
<br>
        -- or perhaps<br>
        import Control.Applicative<br>
        {-# ALLOW redundant_import Control.Applicative #-}<br>
<br>
    allowing the user to explicitly state that they are aware that this<br>
    import may be redundant.<br>
<br>
 4. Attach a `{-# ALLOW redundancy_import #-}` pragma to a name in an<br>
    import list,<br>
<br>
        import Control.Applicative ((<$>) {-# ALLOW redundant_import #-})<br>
<br>
    allowing the user to explicitly state that they are aware that this<br>
    imported function may be redundant.<br>
<br>
In general I'd like to reiterate that many of the comments in this<br>
thread describe genuine sharp edges in our language which have presented<br>
a real cost in developer time during the AMP and and FTP transitions. I<br>
think it is worth thinking of ways to soften these edges; we may be<br>
surprised how easy it is to fix some of them.<br>
<br>
- Ben<br>
<br>
<br>
[1] <a href="https://doc.rust-lang.org/stable/reference.html#lint-check-attributes" rel="noreferrer" target="_blank">https://doc.rust-lang.org/stable/reference.html#lint-check-attributes</a><br>
<br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>