I was reading LYAH. It says I need to explicitly load Control.Monad.Instances
to get the following syntax to work:
( ( fmap (+5) ) (+5) ) 4
Why is that? Why if functors are this underlying and unifying technology do I have to explicitly load Control.Monad.Instances
to get that functionality. How is (->) implemented without it (or is just hidden and only ->
exported)? Why isn't the use of fmap
over function types implemented by default?
There are 3 different concepts involved here. The function type, the Functor type class, and the Functor "instance". The function type, (->), is built into the language and its existence and implementation are completely unrelated to Functor and fmap. The type class is the specification of the signature of its associated methods. The "instance" is an implementation of that signature.
So to make your question clearer, I would re-phrase it as "why isn't the Functor instance for (->) provided in the Prelude?" (the Prelude being the module that's in scope by default). As it is currently phrased, it doesn't make a lot of sense.
The answer to the modified question is simple: the Haskell Report (the official language specification, which is where the Prelude's interface is specified) doesn't include it. Arguably it should, but the Haskell language and libraries have evolved a lot since then, and Haskell standards tend to change slowly. In any case, right or wrong, that's why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With