4

I'm reading some documentation on IxSet's http://happstack.com/docs/crashcourse/AcidState.html#ixset , and I was wondering about looking at source of Indexable typeclass which is imported from Data.IxSet.

So then I took a repository of Happstack and looked there (darcs get http://patch-tag.com/r/mae/happstack), but that got me to even bigger frustration.

I see the happstack/happstack-ixset/src/Happstack/Data/IxSet.hs file, which creates a module Happstack.Data.IxSet, but I can't see which file creates a module Data.IxSet (and implements class Indexable).

Konstantine Rybnikov
  • 2,457
  • 1
  • 22
  • 29
  • the page that you link to gives a link to the package: "IxSet can be found [here on hackage](http://hackage.haskell.org/package/ixset)". Once there, fortunately we have only two modules to check. Click, and we jump to a Haddock doc page. Where we can use a "Find" feature of our browser. When we [find it](http://hackage.haskell.org/packages/archive/ixset/1.0.5/doc/html/Data-IxSet.html#t:Indexable), there's a ["source"](http://hackage.haskell.org/packages/archive/ixset/1.0.5/doc/html/src/Data-IxSet.html#Indexable) link to its right. – Will Ness Jan 13 '13 at 16:55

2 Answers2

5

The go-to address for Haskell code is hackage. There is conveniently a link to Hayoo on the front page, the other major Haskell search engine besides Hoogle. Both have advantages above the other.

Hayoo indexes all packages on hackage and the searches by default include all packages on hackage. If you want to search for a known name, e.g. Indexable, that is the more convenient engine, especially if you don't know which package the name comes from. The - currently - fifth hit takes you to Data.IxSet.Indexable. On the right hand side of the Haddock docs, you find a Source link that takes you to the hscoloured sources (in this case, that's not very informative, though, there's only one class member, without default implementation, it tells you nothing above the docs).

Hoogle searches only a small number of packages by default, if you want to include other packages in the search, you have to specify that by adding +packagename to the search - but that restricts the search to the specified package. More about Hoogle searches in the manual. Hoogle's strength is the search by type. Hoogle's search by type applies more transformations to the searched type, and thus finds more matches than Hayoo's if you don't know the exact type (that is not without downsides, however, sometimes you get a lot of irrelevant hits). If you search for example Map k a -> k -> Maybe a, Hoogle's first result is the most likely candidate Data.Map.lookup :: Ord k => k -> Map k a -> Maybe a, whereas Hayoo doesn't find that because it doesn't permute arguments.

Either way, both search engines lead you to hackage's Haddock docs for the queried entity (if the search was successful), from where the Source links take you to the code, if you wish.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • Daniel, do you know of a (any) (good) way to find a given instance definition? – Will Ness Jan 13 '13 at 16:35
  • Not reliably, since there are a few orphan instances. But checking the module where the class is defined and the module where the type is defined has a good chance of finding it. Otherwise, `:info type` or `:info class` in ghci may tell you where an instance is defined. – Daniel Fischer Jan 13 '13 at 16:42
  • thanks, yes, that's what I know now. IOW, there's no convenient way to find them - searching through actual source file isn't very convenient. And how do I find that source file? `:i` just gives me the name of the source file, not its path. So is it reasonable to say that there's no convenient way to find instances? Isn't this a (huge) disadvantage of Haddock? Can this be improved? – Will Ness Jan 13 '13 at 16:47
  • While I think that it's stupid that you installed code from source (e.g. via cabal) and it cannot keep the source code to let you later look at it by knowing import phrase, I think you're right and it's the current "right way" -- to use a search engine like hoogle or hayoo. I hope in future things will get better and programmers will have ability to just fire ghci and run :source command on any item :) Thanks. – Konstantine Rybnikov Jan 13 '13 at 17:00
  • There may be a convenient way we're just not aware of. To find the source file you got from `:i` (if you got one because both class and type were in scope when you asked), you can check the local haddocks or Hayoo it; yes, not really convenient, and could be improved. But to improve it, you must decide what to implement, and find somebody having the time to implement it and understanding the relevant source well enough to do it. Possible, but given the limited manpower, not to be expected this week. – Daniel Fischer Jan 13 '13 at 17:00
  • @k_bx Yeah, I would like it if cabal unpacked the source somewhere by default too. But the hscoloured sources generated by haddocking take one a long way without needing the actual source files, so I can live with it and `cabal unpack` the packages where I need to look at the actual source. – Daniel Fischer Jan 13 '13 at 17:04
  • Thanks for cabal unpack, I'll take a look at that too! (since it's always better to look at the same version's source that you're using). – Konstantine Rybnikov Jan 13 '13 at 17:07
  • @k_bx and Daniel, conceivably ":source" could fire up a browser and point it to a correct source on hackage too. – Will Ness Jan 13 '13 at 17:08
  • @WillNess I'd prefer if it fired up kwrite opening the local source. – Daniel Fischer Jan 13 '13 at 17:09
  • I meant if there's no local source available. – Will Ness Jan 13 '13 at 17:09
  • Ah, as a fallback, that's quite good. But if it's locally installed, there ought to be source available (one just needs to have cabal keep it unpacked). – Daniel Fischer Jan 13 '13 at 17:11
  • have you happened on an idea of [*provenance*](https://www.google.com/search?q=provenance+programming)? Every bit should know where it comes from. If I'm just using a package, I don't want to mess up the sources - I want it known that the source is not mine so I'd prefer it go to the web. Only if I want to mess around with sources should I make it mine and then it'll live locally. – Will Ness Jan 13 '13 at 17:32
1

Use Haddock documentation, locally-generated or online. Google search usually returns relevant docs near the top. The documentation is cross-linked so you can surf to the module you need. There's a link to the source next to each definition, for example.

This particular module belongs to the base libraries set.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • [Hoogle](http://www.haskell.org/) is also a great place to start if you know the name or type of something but do not know what paackage it is in. – Davorak Jan 13 '13 at 08:14
  • Sorry, but I don't seem to get it. This is Data.Ix, not Data.IxSet (or am I missing something?), and the page you've linked has no "Indexable" class mentioned (so I don't see link to it's definition). – Konstantine Rybnikov Jan 13 '13 at 08:30
  • 1
    Ok, so I used Google, did search for "Data.IxSet" and found http://hackage.haskell.org/packages/archive/ixset/1.0.2/doc/html/Data-IxSet.html#t:Indexable , which is what I need. But is there a non-google way for finding things I need? I mean, I know the module, the classname. How can I find it's source code? Maybe locally somewhere. – Konstantine Rybnikov Jan 13 '13 at 08:33
  • Sorry, [wrong link](http://hackage.haskell.org/packages/archive/ixset/1.0.5/doc/html/Data-IxSet.html). – n. m. could be an AI Jan 13 '13 at 08:36
  • You can build hoogle and haddock locally, and use them from within GHCI (see [GOA](http://www.haskell.org/haskellwiki/GHC/GHCi#GHCi_on_Acid)). – n. m. could be an AI Jan 13 '13 at 08:38
  • Ok, now I get my error. I was looking for happstack/ixset/src/Data/IxSet.hs , not happstack/happstack-ixset/src/Happstack/Data/IxSet.hs . While I still have no Idea how do you find source file by it's import-name, I'm at least not so confused now. – Konstantine Rybnikov Jan 13 '13 at 08:38
  • @n.m. ok, I accept your answer about (possibly local) hoogle, or google. My error with that was that I was searching "Indexable" word and it couldn't find anything, instead I should have searched "Data.IxSet" and then on page of that module searched for "Indexable", then pressed "show source" and by link http://hackage.haskell.org/packages/archive/ixset/latest/doc/html/src/Data-IxSet.html#Indexable guessed that it's about file happstack/ixset/src/Data/IxSet.hs. But there should be a better way to know where file with implementation is located by knowing the import phrase for something. – Konstantine Rybnikov Jan 13 '13 at 08:46