Nostaglia
Nostaglia

Reputation: 43

Why is the type of (.) head ((a -> [c]) -> a -> c)?

I have tried :t (.) head on GHCi and get result (a -> [c]) -> a -> c I get very confuse about this. Could someone give me a hint to help me comprehend this?

For my own thinking, the result should be ([a] -> a -> c)-> a -> c

Upvotes: 4

Views: 127

Answers (2)

Zeta
Zeta

Reputation: 105905

head     ::  [n] -> n
--   b ~ [n]  |     | c ~ n
--            |     |
(.)      ::  (b  -> c) -> (a ->  b ) -> a -> c

(.) head ::               (a -> [n]) -> a -> n

-- rename n to c:         (a -> [c]) -> a -> c

Upvotes: 2

Random Dev
Random Dev

Reputation: 52290

hint:

(.) head 
= \f   -> (.) head f
= \f   -> head . f 
= \f a -> head (f a)

once you have this the rest follows as this:

  • head :: [c] -> c
  • f :: a -> b - so as we do head . f we must have b = [c]

now the complete expression has

\     f              a        -> head (f a)
:: (a -> [c])     -> a        -> c
      ^ type of f    ^ the a     ^ result of head (f a)

Upvotes: 8

Related Questions