我正在使用 GHCi(版本 6.12.3)来玩一下 Haskell。<*>
我最近读到了函子和应用函子,我想如果你不能只使用函子的原语来实现类似于应用函子的东西。经过一番思考,我想出了fmap fmap
一个(几乎)理想的类型
Functor f => f (a -> b) -> f (f a -> f b)
或更笼统地说
(Functor f1, Functor f2) => f1 (a -> b) -> f1 (f2 a -> f2 b)
我试过
let q = fmap fmap
我收到以下错误
<interactive>:1:8:
Ambiguous type variable `f1' in the constraint:
`Functor f1' arising from a use of `fmap' at <interactive>:1:8-16
Probable fix: add a type signature that fixes these type variable(s)
<interactive>:1:13:
Ambiguous type variable `f' in the constraint:
`Functor f' arising from a use of `fmap' at <interactive>:1:13-16
Probable fix: add a type signature that fixes these type variable(s)
按照建议编写上述类型签名没有帮助。最疯狂的是,当我输入时,:t fmap fmap
我得到了与上面相同的类型。
我究竟做错了什么?尽管 GHCi 找到了类型,但为什么会fmap fmap
给出类型错误?