Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't (->) implemented with Control.Monad.Instances by default

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?

like image 902
NO WAR WITH RUSSIA Avatar asked Nov 18 '10 02:11

NO WAR WITH RUSSIA


1 Answers

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.

like image 138
mokus Avatar answered Nov 15 '22 11:11

mokus