How to run HLint?
Asked Answered
H

3

6

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...

Hemicellulose answered 27/11, 2014 at 20:48 Comment(1)
It seems like you have a problem with installing packages in general, rather than HLint in specific, so I suggest you start with the simplest executable, and get that working first. In particular, I suggest you install the hello package (which is incredibly simple) and see if that works.Groscr
D
7

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
Duologue answered 27/11, 2014 at 20:50 Comment(6)
I still don't get it. So I have a file called t.hs with my haskell program. I can open CMD and run that program with no problem. Now you want me to add the line $ hlint t.hs on top of my t.hs file and then run in from CMD like before? I'm getting parse error on input '$' Perhaps you intended to use TemplateHaskellHemicellulose
@isADon: In the CMD window, type hlint t.hs. The dollar sign is just meant to represent the command prompt, you don't actually type it anywhere. Does it give an error if you try to do this?Enchantment
yes I get the command "hlint" is spelled incorrectly or could not be found (translated from german)Hemicellulose
@Hemicellulose I think hlint is not in your PATH. Find where the executable file is present and put that location under the PATH environmental variable. See this link for more details.Duologue
I think something is wrong with my haskell installation. Please see my edit in my question.Hemicellulose
@Hemicellulose If you are starting to learn, I would suggest you to stick with Haskell Platform or use Stackage repo for cabal-install.Duologue
I
2

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/"

Ileneileo answered 27/4, 2018 at 14:29 Comment(0)
L
1

I just run it like this

hlint src/

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

Labors answered 27/11, 2014 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.