我在GHCi中尝试了
根据我的思考,结果应该是
:t (.) head
,得到了结果(a -> [c]) -> a -> c
。我对此感到非常困惑。有人能给我一个提示来帮助我理解吗?根据我的思考,结果应该是
([a] -> a -> c) -> a -> c
。:t (.) head
,得到了结果(a -> [c]) -> a -> c
。我对此感到非常困惑。有人能给我一个提示来帮助我理解吗?([a] -> a -> c) -> a -> c
。提示:
(.) head
= \f -> (.) head f
= \f -> head . f
= \f a -> head (f a)
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)
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
(.)
的第一个参数。 - user253751
([a] -> a -> c) -> a -> c
? - leftaroundabout