haskelltypespolymorphismfunction-compositionhoogle

Why doesn't the type f (f b c) (f (f a b) (f a c)) match (.)?


I have just formulated the type of (.), generalized, as far as I can tell, however, upon typing it into Hoogle, I received no results.

I'd have expected

(.) :: (->) ((->) b c) ((->) ((->) a b) ((->) a c))
     ~ (b -> c) -> ((a -> b) -> (a -> c))
     ~ (b -> c) -> (a -> b) -> a -> c

to match

thistype ~ f (f b c) (f (f a b) (f a c))

Solution

  • The technical answer is that Hoogle splits the search into arguments and return types on the outer (->) parts, and then searches for each part individually, before combining the results. The outer (->) is treated very specially, in particular it's happy to reorder arguments.

    The more fundamental reason why Hoogle works this way is that it's a search engine, not a unification engine. If you were searching for the above, and got back (.), would that have answered your question? My guess is probably not. My favourite example is that searching for "a -> [(a,b)] -> b" should return lookup, even though it doesn't unify.