5

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

Jakub Arnold
  • 79,807
  • 86
  • 218
  • 314
isADon
  • 2,390
  • 5
  • 27
  • 40
  • 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](http://hackage.haskell.org/package/hello) package (which is incredibly simple) and see if that works. – Neil Mitchell Nov 30 '14 at 21:12

3 Answers3

6

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
icc97
  • 8,746
  • 6
  • 60
  • 75
Sibi
  • 43,989
  • 14
  • 80
  • 146
  • 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 TemplateHaskell** – isADon Nov 27 '14 at 20:58
  • 2
    @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? – David Young Nov 27 '14 at 21:04
  • yes I get **the command "hlint" is spelled incorrectly or could not be found** (translated from german) – isADon Nov 27 '14 at 21:12
  • @isADon 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](http://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows) for more details. – Sibi Nov 27 '14 at 21:17
  • I think something is wrong with my haskell installation. Please see my edit in my question. – isADon Nov 27 '14 at 21:25
  • @isADon If you are starting to learn, I would suggest you to stick with [Haskell Platform](https://www.haskell.org/platform/windows.html) or use [Stackage repo](http://www.stackage.org/) for cabal-install. – Sibi Nov 27 '14 at 21:35
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.

jamshidh
  • 11,830
  • 15
  • 30
0

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

Zouzias
  • 2,104
  • 1
  • 19
  • 31