Why type (.) Head ((a & # 8594; [c]) & # 8594; a & # 8594; c)?

I tried :t (.) headon GHCi and got the result. (a -> [c]) -> a -> c I am very embarrassed about this. Can someone give me a hint to help me figure this out?

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

+4
source share
2 answers

hint :

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

once you do this, the rest follows as follows:

  • head :: [c] -> c
  • f :: a -> b- the way we do head . f, we must haveb = [c]

now the full expression has

\     f              a        -> head (f a)
:: (a -> [c])     -> a        -> c
      ^ type of f    ^ the a     ^ result of head (f a)
+8
source
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
+2
source

Source: https://habr.com/ru/post/1615283/


All Articles