Oops... Sorry, wrong line. Should be

isAB :: forall p. p A -> p B -> p x


On 18 Jul 2009, at 10:51, Miguel Mitrofanov wrote:

What is it for? Yes, you would know that only A and B are Public, but you have no way of telling that to the compiler.

I usually prefer something like that:

class Public x where
blah :: ...
isAB :: forall y. (A -> y) -> (B -> y) -> x -> y

Both solutions, however, allow the user to declare some new instances when GeneralizedNewtypeDeriving is enabled.

On 17 Jul 2009, at 19:38, Conor McBride 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

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

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

Reply via email to