There is a Proxy data type in the Data.Tagged library for exactly this purpose, with conversions to and from Tagged. Proxy is easier to use with type annotations, but Tagged seems to be easier for the compiler to erase, since a Proxy is still an argument.
On 26/10/2010, at 19:36, Bas van Dijk wrote:Meh, it's late, just ignore me.
>> How about:
>>
>> malloc :: Storable a => IO (Ptr a)
>> malloc = doMalloc Nothing
>> where
>> doMalloc :: Storable b => Maybe b -> IO (Ptr b)
>> doMalloc dummy = mallocBytes (sizeOf dummy)
>
> I don't think this will work because 'Maybe a' doesn't have a Storable instance.
This is what I was thinking while typing the above nonsense. You could redefine sizeOf and friends to take (Dummy a) instead of `a' as an argument and then use this:
In any case, for me this is not a compelling reason to break several widely used interfaces.
data Dummy a = Dummy
malloc :: Storable a => IO (Ptr a)
malloc = doMalloc Dummy
where
doMalloc :: Storable b => Dummy b -> IO (Ptr b)
doMalloc dummy = mallocBytes (sizeOf dummy)
Roman