Constructor class
Tom Pledger
Tom.Pledger@peace.com
Fri, 19 Oct 2001 09:22:28 +1300
Raul Sierra writes:
| Hi all,
|
| What is the difference between regular classes and constructor classes
| and how do you specify that a class is a constructor class?
|
| Thanks in advance,
| Raul
The term `constructor class' is meant to include classes like Functor
and Monad, whose instances are type constructors but not types.
instance Functor Maybe where ... -- OK, and Functor is a constructor class
foo :: Maybe -- Error, because Maybe isn't a type
instance Eq () where ... -- OK, and Eq is a type class
bar :: () -- OK, because () is a type
There's no particular syntax to distinguish constructor classes from
type classes. It's inferred from the method signatures.
class Functor f where
fmap :: (a -> b) -> (f a -> f b)
-- Here f's kind is inferred as *->* (unary type constructor)
class Eq a where
(==), (/=) :: a -> a -> Bool
-- Here a's kind is inferred as * (nullary type constructor, or type)
Here's a previous thread about kind inference, if you're interested.
http://haskell.cs.yale.edu/pipermail/haskell/2001-February/000489.html
Regards,
Tom