
26 Oct
2009
26 Oct
'09
6:24 p.m.
import Foreign import Foreign.C genericCast :: (Storable a, Storable b) => a -> IO b genericCast v = let dummy = undefined size = max (sizeOf v) (sizeOf dummy) in if False then return dummy else allocaBytes size $ \p -> poke p v >> peek (castPtr p) ---- Code above gives me this: Ambiguous type variable `a' in the constraint: `Storable a' arising from a use of `sizeOf' at src/Bindings/C.hs:28:27-38 ---- It seems to refer to '(sizeOf dummy)'. But isn't the type of 'dummy' defined by 'return dummy' beeing a possible return value (and, so, dummy :: b)? Thanks, Maurício