I've used a similar approach for a while, for instance in <div><br></div><div><a href="http://comonad.com/haskell/type-int/src/Data/Type/Boolean.hs">http://comonad.com/haskell/type-int/src/Data/Type/Boolean.hs</a></div>
<div><br></div><div><a href="http://comonad.com/haskell/type-int/src/Data/Type/Boolean.hs"></a></div><div><div>But I think your approach is cleaner than mine, because it doesn't need my seemingly superfluous closure term or fundep.</div>
<div><br></div><div>-Edward Kmett<br><br><div class="gmail_quote">On Fri, Jul 17, 2009 at 11:38 AM, Conor McBride <span dir="ltr"><<a href="mailto:conor@strictlypositive.org">conor@strictlypositive.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Friends<br>
<br>
Is closing a class this easy?<br>
<br>
--------------------------------------<br>
<br>
module Moo<br>
( Public(..)<br>
) where<br>
<br>
class Private x => Public x where<br>
blah :: ...<br>
<br>
class Private x where<br>
<br>
instance Private A where<br>
instance Public A where<br>
blah = ...<br>
<br>
instance Private B where<br>
instance Public B where<br>
blah = ...<br>
<br>
--------------------------------------<br>
<br>
Modules importing Moo get Public and its instances,<br>
but cannot add new ones: any such instances must be<br>
accompanied by Private instances, and Private is<br>
out of scope.<br>
<br>
Does this work? If not, why not? If so, is this well<br>
known?<br>
<br>
It seems to be just what I need for a job I have in<br>
mind. I want a class with nothing but hypothetical<br>
instances. It seems like I could write<br>
<br>
--------------------------------------<br>
<br>
module Noo<br>
( Public(..)<br>
, public<br>
) where<br>
<br>
class Private x => Public x where<br>
blah :: ...<br>
blah = ...<br>
<br>
class Private x where<br>
<br>
public :: (forall x. Public x => x -> y) -> y<br>
public f = f Pike<br>
<br>
data Pike = Pike<br>
instance Private Pike<br>
instance Public Pike<br>
<br>
--------------------------------------<br>
<br>
But if I don't tell 'em Pike, I've ensured that<br>
blah can only be used in the argument to public.<br>
<br>
Or is there a hole?<br>
<br>
Cures youriously<br>
<br>
Conor<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div></div>