私は 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
型エラーになるのですか?