为什么(.)头的类型((a - > [c]) - > a - > c)?

Nos*_*lia 4 haskell

我试过:t (.) headGHCi并得到结果(a -> [c]) -> a -> c 我对此非常困惑.有人能给我一个提示来帮助我理解这一点吗?

对于我自己的想法,结果应该是 ([a] -> a -> c)-> a -> c

Car*_*ten 8

提示:

(.) head 
= \f   -> (.) head f
= \f   -> head . f 
= \f a -> head (f a)
Run Code Online (Sandbox Code Playgroud)

一旦你有了这个,其余的如下:

  • head :: [c] -> c
  • f :: a -> b- head . f我们必须这样做b = [c]

现在完整的表达了

\     f              a        -> head (f a)
:: (a -> [c])     -> a        -> c
      ^ type of f    ^ the a     ^ result of head (f a)
Run Code Online (Sandbox Code Playgroud)