Question

In haskell, the type of (.) function is:

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

And the type of (.) (.) is:

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

I am not able to deduce the result, how is this done?

Was it helpful?

Solution

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

Let's go through it. First thing this function takes is (b -> c) (so a function from b to c), cool. By adding a pair of (redundant) parentheses:

(.) :: (b -> c) -> ((a -> b) -> a -> c)
       ^-- I am b'  ^-- I am c'   -- (b' and c' not to have name clash)

That first part, we gave to the function (i.e. has been taken care of):

(.) (.) :: (a -> b') -> a -> c'
-- after substituting stuff (b' and c')
(.) (.) :: (a -> (b -> c)) -> a -> ((a1 -> b) -> a1 -> c)
                                    ^-- of course a1 /= a
-- you could eliminate redundant parentheses
(.) (.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c
-- wee

I hope this settles it. Main point is: type inference is easy to 'get' and once you get it is only a matter of substitution to reach what ghci automagically infers. ot: we could call this quizzical operator boobs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top