[Haskell-beginners] functor declaration

Isaac Dupree ml at isaac.cedarswampstudios.org
Thu Jul 1 19:13:39 EDT 2010


On 07/01/10 18:52, Michael Mossey wrote:
> in the declaration of Functor:
>
> class Functor f where
> fmap :: (a -> b) -> f a -> f b
>
> does the compiler infer that f is a type constructor (not a type)
> because of the appearance of "f a" and "f b"?
>
> What I'm thinking is that some classes are classes of types, not type
> constructors. Like
>
> class CanMakeInt a where
> makeInt :: a -> Int
>
> In this case a is a type, not a type constructor. But there is no
> difference in the form of the first line of the class declaration.

You are entirely correct!  The compiler infers this from the entire 
class declaration (or maybe it's the entire module).  The fact that f is 
a type-constructor, or a type, or whatever: that's its "kind", and this 
process the compiler does is called "kind inference".  Only rarely can 
the compiler not figure it out, in which case (per standard) it defaults 
to * (the 'kind' of ordinary types).  (If you use an extension you can 
also specify kinds explicitly, IIRC, like
class Functor (f :: * -> *) where
...
)


More information about the Beginners mailing list