
26 Oct
2009
26 Oct
'09
9:34 p.m.
But isn't the type of 'dummy' defined by 'return dummy' beeing a possible return value (and, so, dummy :: b)?
No. let-bindings are polymorphic, so dummy :: forall a. a
Oh, I once learned that some code of mine didn't work because lambda bindings are monomorphic. Now I can use it for good. genericCast :: (Storable a, Storable b) => a -> IO b genericCast v = return undefined >>= \dummy -> allocaBytes (max (sizeOf v) (sizeOf dummy)) $ \p -> poke p v >> if False then return dummy else peek (castPtr p) In ghci: > let a = 4 :: WordPtr > b <- genericCast a :: IO (Ptr ()) > b 0x00000004 Thanks! Maurício