How to run HLint?

12k views Asked by At

I'm only a few weeks in to programming with Haskell. I was told to use HLint to improve my code. The problem is I can't figure out how to run HLint against my .hs file. I read the documentation and I was able to install it using cabal install hlint. The next step is running HLint using hlint myfile.hs. I can't figure our where to type this line. Neither cmd nor ghci will let me run the command. What am I missing here?

I'm using windows.

edit:

I just removed Haskell and installed it again on my system. I think the problem is with my Haskell installation. Thats what I'm getting when I try to install HLint again: enter image description here

The file does exsist in C:\Users\PCPCPCCP\AppData\Roaming\cabal\setup-exe-cache

edit2:

Seems like hlint wasn't installed correctly. Even after reinstalling the haskell platform I am not able to install hlint it on my system. I did work on my virtual machine however...

3

There are 3 answers

6
Sibi On

Just run it on top of the Haskell file:

hlint filename.hs

You have to run that from the terminal in Linux or the PowerShell/CMD.exe in Windows.

A sample demo from my PC:

$ hlint gem.hs
gem.hs:9:9: Warning: Use void
Found:
  print "if" >> return ()
Why not:
  void (print "if")

gem.hs:10:9: Warning: Use void
Found:
  print "else" >> return ()
Why not:
  void (print "else")

2 suggestions
0
jamshidh On

I just run it like this

hlint src/

where "src/" is the directory defined in the hs-source-dirs: line in my .cabal file.

0
Zouzias On

You need to export the folder of cabal that stores all installed binaries in your environment variable PATH, i.e.,

export PATH="$PATH:$HOME/.cabal/bin/"