I'm using GHCi (version 6.12.3) to play a bit with Haskell. I recently read about functors and applicative functors thought if you couldn't something similar to <*>
of applicative functors be implemented only using functor's primitives. After some thinking I came up with fmap fmap
which would have a (nearly) ideal type of
Functor f => f (a -> b) -> f (f a -> f b)
or more generically
(Functor f1, Functor f2) => f1 (a -> b) -> f1 (f2 a -> f2 b)
I tried
let q = fmap fmap
I got the following error
<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)
Writing the above type signature as suggested didn't help.
The craziest thing is when i typed :t fmap fmap
I got an equivalent type as the above.
What am I doing wrong? Why does fmap fmap
give a type error although GHCi finds a type for it?