I'm learning Haskell for a while, so I've decided to inspect some popular project to get a feeling how it looks like in reality and perhaps reverse-engineer the process.
I've picked Hakyll because it does something I'm familiar with and is moderately complex. And then I've stucked immediately with the question: how to backtrace imports?
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 realize I have no clue where one or another function is located and no clue how to discover it except searching.
Is there some trick to discover this kind of information like making syntax error which would reveal source file or whatever? How do you solve such tasks in your workflow?
Some options which do not require compilable code:
I recommend Stackage's hoogle since its database is loaded with all of Stackage.
If you have working code:
:i
command in ghciAs an example of the last two options, suppose that your have a module Foo.hs
which looks like:
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’
$
If you use Intero for Emacs, it supports the standard "go to definition" shortcut of M-.
.
Other Intero frontends probably use the standard UI of their editor for this functionality as well; I know there's a NeoVim frontend already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With