Proposal: Don't require users to use undefined

Roman Leshchinskiy rl at cse.unsw.edu.au
Tue Oct 26 14:06:22 EDT 2010


On 26/10/2010, at 17:15, Bas van Dijk wrote:

> malloc :: Storable a => IO (Ptr a)
> malloc  = doMalloc undefined
>  where
>    doMalloc       :: Storable b => b -> IO (Ptr b)
>    doMalloc dummy  = mallocBytes (sizeOf dummy)
> 
> I find the use of 'undefined' ugly;

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)

or perhaps

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




More information about the Libraries mailing list