3

I'm trying to disable some warnings that HLint is giving me. According to docs I should be able to add a pragma to the top of my file. So I tried the following:

{-# HLINT ignore #-}
module Main where

Which however gives me an error when running stack build:

/Users/nene/somedir/src/Main.hs:1:1: warning: [-Wunrecognised-pragmas]
    Unrecognised pragma
  |
1 | {-# HLINT ignore #-}
  | ^^^

Seems like the pragma actually works in my editor (VSCode with "Haskell" extension), but is not recognized when running stack.

Rene Saarsoo
  • 12,403
  • 8
  • 51
  • 75

1 Answers1

5

If you want to use a pragma without any warnings, you can use the ANN pragma like this:

{-# ANN module "HLint: ignore" #-}

However I would recommend using a regular comment instead of a pragma:

{- HLINT ignore -}

I prefer regular comments because they don't have weird rules like pragmas do. In fact the documentation notes:

For ANN pragmas it is important to put them after any import statements. If you have the OverloadedStrings extension enabled you will need to give an explicit type to the annotation, e.g. {-# ANN myFunction ("HLint: ignore" :: String) #-}. The ANN pragmas can also increase compile times or cause more recompilation than otherwise required, since they are evaluated by TemplateHaskell.

For {-# HLINT #-} pragmas GHC may give a warning about an unrecognised pragma, which can be suppressed with -Wno-unrecognised-pragmas.

Taylor Fausak
  • 976
  • 7
  • 12
  • Aha... "After any imports". That's the thing I didn't notice when initially attempting to use an ANN pragma. I tried to put it at the beginning of a file, which resulted in really strange parse errors. – Rene Saarsoo Jan 15 '21 at 20:17
  • But you're right. I'll gladly use comments instead. Being a novice at Haskell, I really don't want burden myself with learning pragmas right now. – Rene Saarsoo Jan 15 '21 at 20:20
  • 2
    @ReneSaarsoo: I think the only pragma you really need to be aware of as a beginner is `LANGUAGE`, which explicitly enables language features. You may also see `OPTIONS_GHC` sometimes for specifying extra compiler options. You can ignore others until you need them; they control more advanced optimisations, warnings, and type system features. Also, pragma names are case-insensitive, so you can write e.g. `{-# Language BlockArguments #-}` if you prefer. – Jon Purdy Jan 15 '21 at 21:02