Haskell Code Tools
Types offer more than just safety
● Haskell provides structure to assist source navigation tools
● Often overlooked. Most people I pair with don’t use this stuff.
● Only danger: you get addicted to it.
Things we’ll do
● Find Code● Find Problems● Find Docs● Autocomplete● Format Code
First the tools themselves, then editor support
Hasktags Experiments
● Demonstrate it with “-o -”● Try the options, and notice the problem of
“close implementations”● Combine with grep for primitive lookup
Find Code
ALL THE SYMBOLS!
codex
“the xargs of cabal”It requires some configuration(Stack support in progress)
Codex
● Inspect the configuration file, ~/.codex● Watch it at work by swapping command
○ tagsCmd: echo '$SOURCES' >> '$TAGS'● Considerations of full paths
○ Perhaps helps the editor jump to correct file○ But makes tags file break if dir moved
Find Code
Callers of a symbol (the opposite direction)
hscope
More accurate than ack, since hscope is aware of syntax.
hscope
● First build an index with -b○ git ls-files | grep '\.l\?hs$' | xargs
hscope -b "$@"● Perhaps codex would be nice here, but
would need a new config file● Then we can use -3 to find callers● Other features too, in a way subsumes
hasktags, but want vim ctags support
Hoogle
● Location of db is compiled into the binary● Override when installing
○ cabal install hoogle \ --datadir=/foo/bar
● Two basic ways to populate db○ hoogle data○ hoogle data all
● The second one builds everything!
Getting the Hoogle db right
● If you include too many packages your searches can yield false positives
● And too few is of course bad.● Default “hoogle data” installs 42 of the most
popular packages● And “hoogle data all” drags in all of hackage● ...What about tailored per project dbs?
Hoobuddy
● To examine a project and build a custom hoogle db you can use hoobuddy
● hoobuddy fetch <project.cabal>● Creates default.hoo in the current
directory which is the first place hoogle looks● Have to compile with same db location as
hoogle
Alfred Shortcuts
● A mac thing● Hackage
○ https://hackage.haskell.org/packages/search?terms={query}
● Stackage Hoogle○ http://www.stackage.org/lts-2.17/hoogle?q={query}
● Also Hackage-Fu extension for Chrome
Find problems
● Quick feedback with ghc-mod● ghc-mod check filename● Checks the file without creating any output
Find (potential) problems
● hlint file-or-directory● Like having a Haskell teacher sit over your
shoulder● Ignore warnings of your choice with HLint.hsimport "hint" HLint.Defaultignore "Eta reduce"
● Enable in continuous integration
Autocomplete
● The fuel for in-editor suggestions● Find the materials with ghc-mod● ghc-mod list to see visible modules● ghc-mod browse
○ options to show types● ghc-mod lang to see extensions● ghc-mod type easier to demo in an editor
Auto formatting
● Many dislike Haskell’s touchy indentation● Use stylish-haskell for a quick touchup
○ Cleans up import statements and data records○ demo with icdiff○ Hard-coded config path, try -v to see
● Or try the big (slow) guns, hindent○ Choose from “styles”○ Layout algorithms inspired by actual Haskellers
● Git commit hook to end all arguments
demo
● Try PostgREST/Auth.hs● gq on imports● find uses of e.g. setRole● where is something
defined?● type inspect cs function● hlint after removal● check correctness
● Autocomplete from sandbox
● tt for ghc-mod list
● hoogle search and info
Try it and Contribute Back
http:// github.com / begriffs / haskell-vim-now
● One-line installer● Backs up your configuration● Installs necessary tools to your system