Hari Krishna
Hari Krishna

Reputation: 3538

Haskell: need to understand signature of Functor

Can some body explain me the signature of Functor.

Prelude> :info Functor
class Functor (f :: * -> *) where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a

I don't understand what * means.

Upvotes: 3

Views: 363

Answers (1)

Random Dev
Random Dev

Reputation: 52270

* is the syntax used by Haskell for kinds

In this case it means that f is higher-kinded (think functions on the type level)

Here f is taking one type (the first *) and is producing another type (the second *)

you can basically forget all this here and just read it as:

class Functor f where
  fmap :: (a -> b) -> f a -> f b
  (<$) :: a -> f b -> f a

but it's a nice documentation IMO and there are quite a few classes that are more complicated and the kind-signature is really helpful - for example:

class MonadTrans (t :: (* -> *) -> * -> *) where
  lift :: Monad m => m a -> t m a
        -- Defined in `Control.Monad.Trans.Class'

Here t takes a type-constructor itself (the Monad) together with another type and produces a type again.

Upvotes: 6

Related Questions