Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different among hlint, hdevtools and ghc-mod

Tags:

haskell

I am looking for code lint, type query, auto type-insert and misc helper to use with vim (like autocomplete).

After some research I found multiple similar tools that migth do what I want

  • hlint
  • hdevtools
  • ghc-mod

The main question, Are these all basically the same tool?

When I do some testing I found that only ghc-mod is working out-of-the-box (for code lint, havn't try any Type-helper function)

$ cat test.hs 
main = putStrLn "test"
$ ghc-mod check test.hs 
test.hs:1:1:Warning: Top-level binding with no type signature: main :: IO ()
$ hdevtools check test.hs 
Run from outside a project, using implicit global project config
$ hlint test.hs 
No hints

Do I need to make any configuration file for hlint and hdevtools?

$ hdevtools --version
hdevtools: version 0.1.4.1 (ghc-8.0.1-x86_64-linux, cabal-1.24.0.0)
$ hlint --version
HLint v1.9.35, (C) Neil Mitchell 2006-2016
$ ghc-mod --version
ghc-mod version 5.6.0.0 compiled by GHC 8.0.1
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1

All tools was installed by stack install and I have /home/wizzup/.local/bin in $PATH

like image 835
wizzup Avatar asked Oct 19 '16 12:10

wizzup


1 Answers

ghc-mod installs a binary named ghc-mod to your $PATH which is able to load and interrogate your package database and source code (there is also an "interactive" version called ghc-modi that reads in commands from standard in and sticks around). It uses the GHC and Cabal APIs to do so. Progress stalled for a while but has now returned to a bustling state. There are Emacs/Vim/Sublime packages that know how to talk to ghc-mod and provide various IDE-like features for end-users: typechecking, holes, program/proof search, find-definition.

hdevtools is a newer project, inspired by ghc-mod. It is architecturally similar – running a persistent background server with per-editor packages. It is designed to completely replace ghc-mod. The differences between ghc-mod and hdevtools seem to be philosophical. hdevtools has fewer of the fancy ghc-mod features but is (in my experience) substantially faster. Something that struck out from a cursory glance at the code bases: hdevtools seems to rely on the GHC API to implement a GHCi-like server, capable of quickly reloading code. Perhaps that was the key decision to getting good performance? I am sure I am grossly oversimplifying.

hlint is very different. It is an old old project (started in 2006 by Neil Mitchell, one of the Haskell community elders). It is able to detect typical bad Haskell habits (e.g. using concat . map instead of concatMap) and, in some cases, lightly refactor them away. It relies on the haskell-src-exts which parses Haskell code into ASTs. I believe hlint does not even require a full type-check of the code base: it can look at the abstract syntax tree alone to suggest changes and sound alerts. You would typically choose either ghc-mod or hdevtools and use them in conjunction with hlint to get the full Haskell IDE experience.

We should take the time here to also mention FP Complete's intero project, which runs ghci and is similar to hdevtools. It only works if your editor is Emacs and you are using stack, however. I was unable to find good documentation on how it differs from ghc-mod or hdevtools; one presumes it was intended to give Emacs users a better experience, as you can often get into the situation where hdevtools/ghc-mod will stubbornly refuse to run because of a compiler or an editor package mismatch. With intero you can get up and running with a small snippet of Elisp.

It's a big old mess!

like image 152
hao Avatar answered Oct 17 '22 08:10

hao