有人可以解释一下如何手动推断此函数f的类型吗? f =地图(。) (:)甚至
我想逐步了解解决方案,以解释与优先级和事物有关的事情。
预先感谢!4
答案 0 :(得分:1)
步骤1:解析:
f = (map (.)) . ((:) even)
第2步。推断某些类型:
(.) :: (b -> c) -> (a -> b) -> (a -> c)
map (.) :: [b -> c] -> [(a -> b) -> (a -> c)]
(:) :: d -> [d] -> [d]
(:) even :: Integral e => [e -> Bool] -> [e -> Bool]
第3步。推导一些方程式:
x = [e -> Bool] -- the output of (:) even
x = [b -> c] -- the input to map (.)
e = b
c = Bool
第4步。记下f
的类型:
f :: [(a -> b) -> (a -> c)]
f :: Integral e => [(a -> e) -> (a -> Bool)]