【发布时间】:2020-05-04 13:14:23
【问题描述】:
我不明白这个简单的表达式类型在 Haskell 中是如何检查的
(fmap.fmap) sum Just [1, 2, 3]
fmap的组合类型为:
fmap.fmap
:: (Functor f1, Functor f) => (a -> b) -> f (f1 a) -> f (f1 b)
所以我期望 f1 ~ List 和 f ~ Maybe,这意味着函数的类型应该是 Integer -> b。但是如果在 ghci 中对它进行类型检查,我会得到:
t (fmap.fmap) _ Just [1, 2, 3]
<interactive>:1:13: error:
• Found hole: _ :: [Integer] -> b
Where: ‘b’ is a rigid type variable bound by
the inferred type of it :: Maybe b at <interactive>:1:1
• In the first argument of ‘fmap . fmap’, namely ‘_’
In the expression: (fmap . fmap) _ Just [1, 2, 3]
我看到 ghci 将函数的类型推断为 [Integer] -> b。这怎么可能?
【问题讨论】:
标签: haskell