Haskell - fmap fmap not working

I use GHCi (version 6.12.3) to play a bit with Haskell. Recently I read about functors and applicative functors, I thought that if you cannot <*>implement something like applicative functors only using primitive functors. After some thought, I came up fmap fmapwith one that would have a (almost) perfect type

Functor f => f (a -> b) -> f (f a -> f b) or more general

(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 type signature above did not help. The craziest thing when I typed :t fmap fmapwas to get the equivalent type as above.

What am I doing wrong? Why fmap fmapdoes it give a type error, although GHCi finds a type for it?

+5
2

, .

GHCi -XNoMonomorphismRestriction .

, let f x = fmap fmap $ x. , , .. f = something, . , (, where). . .

+7

, . , , , ​​ . ghci , , , ?

Prelude> let q :: (Functor f) => f (a -> b) -> f (f a -> f b); q = fmap fmap
Prelude> :t q
q :: (Functor f) => f (a -> b) -> f (f a -> f b)

Prelude> let q :: (Functor f1, Functor f2) => f1 (a -> b) -> f1 (f2 a -> f2 b); q = fmap fmap
Prelude> :t q
q :: (Functor f1, Functor f2) => f1 (a -> b) -> f1 (f2 a -> f2 b)
+1

All Articles