문제

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?

도움이 되었습니까?

해결책

(.) :: (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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top