[Haskell-cafe] Exporting a Type Class for Type Signatures
wren ng thornton
wren at freegeek.org
Mon Nov 10 17:08:40 EST 2008
Bulat Ziganshin wrote:
> Hello Dominic,
>
> Monday, November 10, 2008, 10:56:37 PM, you wrote:
>
>> but this generates an error. Is there a way of allowing someone to use
>> AESKey in a type signature but not allow them to declare new instances?
>
> afaik
>
> module AES (class AESKey,...)
This seems not to work on ghc6.8.2 at least.
$ cat AClass.hs ; ghc AClass.hs
module AClass (class A) where
class A a where f :: a -> ()
instance A () where f = id
AClass.hs:1:15: parse error on input `class'
Alas I don't know of any way to export a class for type signatures
without exporting it for instantiation (corrections welcome :)
There is, however, a fairly canonical hack if you're only concerned with
the correctness of the code in your own library. You create an extra
(empty) public class which is only an indirection for the real private
class; and make sure your library only uses the real class. This way,
even though clients can make new instances on the public class, that
won't affect your own code.
If your goal is to try to ensure the correctness of client code (not
just the correctness of the library code), this trick doesn't help though.
--
Live well,
~wren
More information about the Haskell-Cafe
mailing list