Difference between revisions of "User:Zzo38/Proposal about classes"

From HaskellWiki
Jump to navigation Jump to search
Line 28: Line 28:
 
==Classes of classes==
 
==Classes of classes==
 
See proposal of kinds.
 
See proposal of kinds.
  +
  +
==See also==
  +
* [[Superclass defaults]]
  +
  +
[[Category:Proposals]]

Revision as of 20:28, 3 September 2011

This document is proposal relating to various things dealing with classes in Haskell.

Monads

Move join into the Monad class, to allow monads to defined in terms of unit/join/fmap. Together with things described below, it can automatically be Functor as well, and define fmap if you are using return/bind definitions.

Default superclass definitions

For example, for monads you can have:

class Functor m => Monad (m :: * -> *) where {
  (>>=) :: forall a b. m a -> (a -> m b) -> m b;
  (>>) :: forall a b. m a -> m b -> m b;
  return :: a -> m a;
  join :: m (m a) -> m a;
  fail :: String -> m a;
 
  a >>= f = join $ fmap f a;
  m >> k = m >>= \_ -> k;
  join = (>>= id);
  fail = error;
 
  fmap f m = m >>= return . f;
};

In this case, you can define the defaults for Functor if they are not already defined.

Restrictive classes

For example, make a restrictive monad that only contains instances of Ord. I am not sure about syntax or other details.

Classes of classes

See proposal of kinds.

See also