I've used a similar approach for a while, for instance in 

http://comonad.com/haskell/type-int/src/Data/Type/Boolean.hs

But I think your approach is cleaner than mine, because it doesn't need my seemingly superfluous closure term or fundep.

-Edward Kmett

On Fri, Jul 17, 2009 at 11:38 AM, Conor McBride <conor@strictlypositive.org> wrote:
Friends

Is closing a class this easy?

--------------------------------------

module Moo
 (  Public(..)
 )  where

class Private x => Public x where
 blah :: ...

class Private x where

instance Private A where
instance Public A where
 blah = ...

instance Private B where
instance Public B where
 blah = ...

--------------------------------------

Modules importing Moo get Public and its instances,
but cannot add new ones: any such instances must be
accompanied by Private instances, and Private is
out of scope.

Does this work? If not, why not? If so, is this well
known?

It seems to be just what I need for a job I have in
mind. I want a class with nothing but hypothetical
instances. It seems like I could write

--------------------------------------

module Noo
 (  Public(..)
 ,  public
 )  where

class Private x => Public x where
 blah :: ...
 blah = ...

class Private x where

public :: (forall x. Public x => x -> y) -> y
public f = f Pike

data Pike = Pike
instance Private Pike
instance Public Pike

--------------------------------------

But if I don't tell 'em Pike, I've ensured that
blah can only be used in the argument to public.

Or is there a hole?

Cures youriously

Conor

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe