[Haskell-cafe] Problem trying to get class Bounded to work

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Tue May 23 10:56:38 EDT 2006


Jacques Carette wrote:
> Bulat Ziganshin wrote:
> 
> >malloc :: Storable a => IO (Ptr a)
> >malloc  = doMalloc undefined
> > where
> >   doMalloc       :: Storable b => b -> IO (Ptr b)
> >   doMalloc dummy  = mallocBytes (sizeOf dummy)
> > 
> >
> Is there any reason to not code this as
> 
> malloc :: Storable a => IO (Ptr a)
> malloc  = mallocBytes $ sizeof undefined

What type would the 'undefined' have in this context?

sizeOf has type Storable a => a -> Int -- that doesn't help.

The purpose of doMalloc is to force the type checker to choose
the right type for that 'undefined'.

regards,

Bertram


More information about the Haskell-Cafe mailing list