Search code examples
haskelltypesfunctional-programmingunify

Unifying Types in Haskell


I'm kind of stuck with an assignement concerning my exams. I want to find out the types of those two functions by applying the unifying algorithm by hand:

map map
(\x -> x >>= (\y -> y))

Could someone point me to the right direction? The only ressource I could find until now was the wikipedia entry which is not really aiding me because of the high level of abstraction.

Greetings and thank you.


Solution

  • Let's just do the first.

    map :: (a -> b) -> [a] -> [b]
    

    Now we can write it again with two different names, for clarity:

    map :: (c -> d) -> [c] -> [d]
    

    Now we substitute the second as the first parameter of the first, getting:

    (a -> b) === (c -> d) -> ([c] -> [d]) (recall the associativity of (->))
    a === (c -> d)
    b === ([c] -> [d])
    

    Now we substitute those type assignments into the remaining portion of the first signature, getting

    map map :: [c -> d] -> [[c] -> [d]]
    

    Clear?