Hacker News new | comments | show | ask | jobs | submit login

Haskell helps you develop your imagination:

> I have no idea what the word "boo" is supposed to mean when used as a function name. But I can be almost certain what this "boo" does. It takes a map that has Integer keys and String values, and a second argument that is just a String, and it returns an Integer. So I'm fairly sure that this function does a reverse mapping

Actually its just deductive reasoning. Because that example is a pure function, you know there is little else it could be doing. The only question in fact would be whether or not it is doing a transformation on the value before returning it.

Things it could be doing:

* Counts the values that have the second argument as a substring

* Returns key that, using some fuzzy string algorithm, matches the second argument the closest

* Computes a score from matching the second argument against the map, which tracks document occurrences in a search engine type gizmo

I don't think the meaning is obvious at all. If anything it's a lesson in naming stuff: Don't call your functions "boo".

The actual function would be written more like

    invMap :: forall k v. (Eq v, Eq k) =>
              Map k v -> v -> Set k
The parametricity means that while this function may get specialized to have v ~ String and k ~ Int, we can be sure that invMap isn't using that information. Instead, with the typeclass restriction, we know that the only thing the function can be doing internally to the ks and vs is comparing them for equality.

Intuitively, invMap can either be computing the Set of ks which hold a particular v or, maybe, the set of ks which don't hold that value and not much else.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact