hoogle
hoogle copied to clipboard
Support search for type instances
Search input:
instance Serialise Text
Current result: Nothing
Expected result:
cereal-text::Data.Serialize.Text
Context: automating type instance discovery with haskell-language-server (this is a blocker for the implementation) https://github.com/haskell/haskell-language-server/issues/2957
What needs to be done to make hoogle to do that?
Is this useful if you don't have orphan instances? Given that orphan instances are generally frowned upon, Hoogle doesn't really take them into account when searching or building its database, and I can't imagine that it will in the near future.
Searching for type instances seems to me like a thing that might be more useful in general. E.g., what type instances are exposed by a certain package for a type, for example.
Being able to search for orphan instances does have a use-case, as described here, there are packages that have lots and lots of instances, but factor them out into special orphan packages to reduce the dependency footprint. I suppose, we can argue that you shouldn't do that and rather use explicit feature flags (however, cabal has basically no support for such a feature).
Anyway, to me, it sounds like a feature that satisfies a real need. To not encourage users to use orphan instances when it is not appropriate, maybe we can hide searching for orphan instances behind a scope specifier? E.g. Serialiase Text instances:orphans. This way, newer users aren't accidentally encouraged to depend on some package that happens to implement the type class, but more experienced users still can use the feature, and HLS can provide a simplified interface for users to find these instances.
A feature behind a scope identifier is one that nearly no one will ever find or use, so has implementation complexity but not really much benefit. Hoogle is a search engine for humans. It feels like you want point-information about only orphan instances (since if they weren't orphans, they would already be in scope). I'm not sure that belongs in Hoogle, but if it could be added reusing existing information or cheaply, then maybe it's not a perfect fit, but good enough. Looking at the code, Hoogle certainly ingests instances (https://github.com/ndmitchell/hoogle/blob/master/src/Input/Item.hs#L81), but it's only used in name ranking to figure out which instances are popular or not. As far as I can tell, the actual instances don't make it into the database at all, so the information is completely unavailable when searching.
E.g. I want to find the package that defines instance Arbitrary (Data.List.NonEmpty _). How can I do this?
How much work would it be to get the command-line tool to recover things analogous to whatever already gets listed in hackage for the types that are instances of classes and the classes that types are instances of without a great deal of search intelligence wrt. wildcards or orphan instances?