Consider the following GHCi decoding, version 8.2.2:
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Prelude> :set -XRankNTypes
Prelude> data Functor f = Functor { fmap :: forall a b. (a -> b) -> f a -> f b }
Prelude> :t fmap
fmap :: Functor f1 -> (a -> b) -> f2 a -> f2 b
Prelude> :t Functor map
Functor map :: Functor []
Prelude> :t fmap (Functor map)
fmap (Functor map) :: (a -> b) -> [a] -> [b]
As you can see, the type fmapis inferred as Functor f1 -> (a -> b) -> f2 a -> f2 b. This is surprising because f1, and f2must be the same type variable, but there is no limit f1 ~ f2. However, if you apply fmapto Functor mapwhich has a type Functor [], the result still has the type (a -> b) -> [a] -> [b]as expected. What's going on here? I would expect fmapto have a type Functor f -> (a -> b) -> f a -> f b.
source
share