Why define a functor instance for a 'nameless' type like `(->) e`

Viewed 117

In Haskell GHC base has definitions of a Functor instance for a type (->) r:

instance Functor ((->) r) where
    fmap = (.)

Typeclassopedia explains ((->) e) is the type of functions which take a value of type e as a parameter. This makes sense, but I'm lost how (->) e is used later, compared to Maybe, Either a, even [].

I think I understand these functor definitions, which are named: Maybe, Either a, but I have a hard time understanding how a 'nameless' type (->) r is used.

Does this mean I need to suspect any other a -> in every type signature as functor? Is this a way of defining the properties of arrow -> in Haskell?

Also is this the same arrow as in type signatures or an arrow from lambda functions? I tried looking up in Haskell report, but there -> is used in own notation for documentation, so no luck there.

Thanks in advance for any hints that can help breaking the ice around (->) r.

Update: based on comments I think I should be asking where -> type constructor defined? is it a built-in?

The answer to that is -> is built in, and it is a "function arrow" or "function type constructor".

1 Answers

(->) r is not a nameless type. Its name is (->), just like Either is a name. In fact if you write a -> b, you wrote (->) a b. Or if you write a -> b -> c, then the canonical form is (->) a ((->) b c).

(->) is a type constructor, just like Maybe, Either, etc. The fact that it is used as an infix operator is not that odd. If you write x : xs for example, then the canonical form is (:) x xs (or more verbosely ((:) x) xs). If you enable the TypeOperators extension, you can even write types like Left 1 :: Int `Either` String.

Related