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
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to