Class Multiplicity

Ashley Yakeley ashley@semantic.org
Thu, 16 May 2002 23:48:58 -0700


I have a curious Haskell design pattern. It's called "one class per 
function". It's strange, but I find that as I need more and more 
generality, I end up with classes that look like this:
	
    class (Monad m) => MonadGettableReference m r where
        {
        get :: forall a. r a -> m a;
        };
	
    class (Monad m) => MonadSettableReference m r where
        {
        set :: forall a. r a -> a -> m ();
        };

...and then I'll have a bunch of "joining" classes. Here's a joining 
class:

    class
        (
        MonadGettableReference m r,
        MonadSettableReference m r
        ) => MonadFixedReference m r;

    instance
        (
        MonadGettableReference m r,
        MonadSettableReference m r
        ) => MonadFixedReference m r;

Sooner or later, for maximum generality they're all going to look like 
this:

    class Foo a where
        {
        foo :: a;
        };

    class Bar a where
        {
        bar :: a;
        };

    class
        (
        Monad m,
        forall a. Foo (a -> m a), -- pending appropriate extension
        forall b. Bar (m b)
        ) => FooBar m;

    instance
        (
        Monad m,
        forall a. Foo (a -> m a),
        forall b. Bar (m b)
        ) => FooBar m;

I'm not sure if this is a good thing or a bad thing or what.

-- 
Ashley Yakeley, Seattle WA