[Haskell-beginners] Various style at instance of a typeclass

Stephen Tetley stephen.tetley at gmail.com
Wed Jun 29 18:05:46 CEST 2011


On 29 June 2011 16:36, Haisheng Wu <freizl at gmail.com> wrote:

> Well, how did you know Monad is with kind :: * -> * ?

If I was looking at the docs I'd see these two pieces

> class Monad m where
> (>>=) :: forall a b. m a -> (a -> m b) -> m b

As (m a) and (m b) are used in the method (>>=) and but only m is
specified in the class declaration, it would tell me m is :: * -> *.


There is an extension in GHC (probably {-# LANGUAGE KindSignatures #-}
) where you can specify kinds in the class declaration:

> class Monad (m :: * -> *) where

Personally I wouldn't be upset if this was the only valid syntax -
it's redundant but I find it clearer.

I'm not sure what references are available. I think constructor
classes were originally implemented in Gofer (a Haskell variant) and
when they were in Gofer but not Haskell, people seemed to make a clear
distinction between the two. Nowadays people just call them "type
classes" and have got used to the kinds of the common classes.



More information about the Beginners mailing list