Class Multiplicity

Andrew J Bromage andrew@bromage.org
Sat, 18 May 2002 17:41:52 +1000


G'day all.

On Thu, May 16, 2002 at 11:48:58PM -0700, Ashley Yakeley wrote:

> I have a curious Haskell design pattern. It's called "one class per 
> function".

When used in conjunction with fundeps, I call it "hacking C++-style
function overloading".

Sometimes I think it would be handy if the Prelude used it more,
because then you could have full overloading for types which don't
quite play by the rules of the standard classes.  For example:

	class Mult a b c | a b -> c where
		(*) :: a -> b -> c

	class Add a b c | a b -> c where
		(+) :: a -> b -> c

	{- etc -}

	class (Mult a a a, Add a a a, {- etc -}) => Num a where
		{- etc -}

Then you could use the standard notation to multiply matrices with
vectors and Haskell wouldn't complain.  I'm not sure that this is
necessarily something to be encouraged, of course...

Cheers,
Andrew Bromage