
On Tue, Oct 26, 2010 at 9:36 PM, Roman Leshchinskiy
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)
Yes, this is another possibility. It doesn't require undefined but does require a dummy argument which is only used to help the type checker.
In any case, for me this is not a compelling reason to break several widely used interfaces.
Fair enough. However I find the following much easier to read (no auxiliary function and no dummy argument): malloc :: forall a. Storable a => IO (Ptr a) malloc = mallocBytes (untag (sizeOf :: SizeOf a)) Bas