[Haskell-cafe] Exporting a Type Class for Type Signatures

Antoine Latter aslatter at gmail.com
Mon Nov 10 17:24:05 EST 2008


On Mon, Nov 10, 2008 at 1:56 PM, Dominic Steinitz
<dominic.steinitz at blueyonder.co.uk> wrote:
> In the crypto package, I have two functions
>
>> encrypt :: AESKey a => a -> Word128 -> Word128
>> decrypt :: AESKey a => a -> Word128 -> Word128
>
> which are exported.
>
> I also have
>
>> class (Bits a, Integral a) => AESKey a
>>
>> instance AESKey Word128
>> instance AESKey Word192
>> instance AESKey Word256
>
> unexported which stops you using invalid keys.
>
> Someone has asked me to export AESKey as they want to write an explicit
> type signature for a function they are creating e.g.
>
> foo :: AESKey a => a -> Word128 -> Word128
> foo x y = encrypt x y
>
> 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?
>
> Thanks, Dominic.
>

Is there anything wrong with:

> encrypt :: AESKey -> Word128 -> Word128

> data AESKey = Key128 Word128  | Key192 Word192 | Key256 Word256

Aside from the obvious that it's a breaking interface change.

-Antoine


More information about the Haskell-Cafe mailing list