Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

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

like image 797
Nostaglia Avatar asked Dec 25 '22 12:12

Nostaglia


2 Answers

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)
like image 103
Random Dev Avatar answered Jan 03 '23 04:01

Random Dev


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
like image 41
Zeta Avatar answered Jan 03 '23 03:01

Zeta