Find function source in Haskell (workflow)

I’ve been studying Haskell for a while, so I decided to check out some popular project to understand what it really looks like and possibly reconstruct the process.

I chose Hakyll because it does what I am familiar with and moderately complex. And then I immediately launched the question: how to return the import?

Say in JavaScript, every import is explicit.

let Q = require("Q") // namespace let {foo} = require("Q/foo") // value 

Haskell defaults to

 import Q 

which spoils everything at once, and people seem to really abuse it.

Now I look at the tutorial , then at the source and I understand that I do not know where this or that function is located, and I do not know how to detect it except for the search.

Is there any trick to detect information such as making a syntax error that will open the source file or something else? How do you solve such problems in your workflow?

+5
source share
3 answers

Some options that do not require compiled code:

I recommend Stackage hoogle since its database is loaded with all Stackage.

If you have working code:

  • use command :i in ghci
  • use ghc-mod through your editor or command line.

As an example of the last two options, suppose you have a module Foo.hs that looks like this:

 module Foo where import Data.Maybe ... 

Using ghci :

 $ ghci Foo.hs GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Foo ( Foo.hs, interpreted ) Ok, modules loaded: Foo. *Foo> :i catMaybes catMaybes :: [Maybe a] -> [a] -- Defined in 'Data.Maybe' *Foo> 

Using ghc-mod :

 $ ghc-mod info Foo.hs catMaybes catMaybes :: [Maybe a] -> [a] -- Defined in 'Data.Maybe' $ 
+6
source

If you use Intero for Emacs , it supports the standard M-. shortcut M-. .

Other Intero interfaces probably also use their editor’s standard interface for this function; I already know the NeoVim interface .

+4
source

If you want this kind of code support in Haskell supported in vim , you can try Steven Dichl a good Vim and Haskell tutorial in 2016 .

Haskell has many editing environments that allow you to query the GHC compiler for information about the code. For example, I use vim-hdevtools and I can open the hakyll/src/Hakyll/Main.hs in vim , move the cursor over the Commands.build symbol, enter the command :HdevtoolsInfo , and then GHC will tell me the type of symbol and its definition and give me the opportunity to move on to the definition.

 Commands.build :: Config.Configuration -> Logger.Logger -> Rules a -> IO ExitCode -- Defined at hackyll/src/Hakyll/Commands.hs:48:1 

However, I admit, I spent a lot of time getting vim-hdevtools to work .

0
source

All Articles