ndmitchell / hoogle

Haskell API search engine
http://hoogle.haskell.org/
Other
738 stars 134 forks source link

hoogle.haskell.org not finding results #352

Open jluttine opened 4 years ago

jluttine commented 4 years ago

I typed in the search field: f (g a) -> g (f a) but hoogle didn't find any results.

However, if I type distribute, one of the search results is distribute :: (Distributive g, Functor f) => f (g a) -> g (f a) which has the type I was looking for originally.

Why doesn't hoogle find it? Am I doing something wrong?

ndmitchell commented 4 years ago

If I search for literally (Distributive g, Functor f) => f (g a) -> g (f a) then it's the second result, after another which has the same type. Dropping the Functor constraint gives the same answer. But the Distributive constraint is considered key because Distributive is quite a rare type - your type doesn't have a lot of structure (basically nothing), so Hoogle decides the Distributive is a super important constraint, and it roughly does a search on that name alone, then filters the results. It might be possible to tweak the algorithm, especially in the case where nothing comes back, but it is working "as designed" at the moment.

jluttine commented 4 years ago

Ok, thanks for the answer! I'm not sure I fully understood, but is the problem that there are too many results if the query lacks Distributive g constraint? So, hoogle doesn't want to show too many results? Sounds a bit counter-intuitive to me. For instance, I have never experienced google search engine saying that there are too many results, so maybe that's why I have difficulties understanding the issue.

My usecase was that I was trying to figure out what kind of typeclass constraints enable me to use type f (g a) -> g (f a). So, I couldn't write those constraints because they were the things I didn't know and wanted to learn. I didn't know about Distributive, and actually, what I was after in the end, was (Traversable t, Applicative f) => t (f a) -> f (t a). That is, I just knew what kind of structural changes I wanted for my type, but I didn't know what functions there exist for that and what typeclass requirements they have. At least for me, this is a very typical usecase for hoogle, so I would love if it worked for this. Or do you know if there's some other useful method for finding such information?

Or if hoogle fails because of too many results, perhaps the error message could be "Too many results found" instead of "No results found"?

ndmitchell commented 4 years ago

I wrote a post to answer your questions about how Hoogle works: https://neilmitchell.blogspot.com/2020/06/hoogle-searching-overview.html. There's not really such a thing as too many results - there are almost always loads of results, of varying quality, from the first pass, and we take the top ones.

Unfortunately, it's not well set up for the kind of problem you are describing... I don't know of any tool to do what you are after. There's an option that the fingerprint could be extended with a hash of the structure of the type, and that could give signal, but I worry it's solving exactly the problem you had last, not the general form of the problem.