Is it possible to create a typeclass that can no longer admit new members (perhaps by using module boundaries)? I can refuse to export a function necessary for a complete instan
Since GHC 7.8.1, closed type families can be declared, and I think with the help of them, and ConstraintKinds
, you can do this:
type family SecretClass (a :: *) :: Constraint where
SecretClass Int = ()
SecretClass a
forms a constraint, equivalent to a type class, and since the family can't be extended by anyone, no other instances of the "class" can be defined.
(This is actually just speculation, since I can't test it, but the code in this interesting link makes it look like it would work.)