Proposal: Don't require users to use undefined

Roman Leshchinskiy rl at cse.unsw.edu.au
Tue Oct 26 15:36:17 EDT 2010


On 26/10/2010, at 19:36, Bas van Dijk wrote:

>> 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.

Meh, it's late, just ignore me.

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:

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)

In any case, for me this is not a compelling reason to break several widely used interfaces.

Roman




More information about the Libraries mailing list