[Haskell-beginners] Why is this type ambiguous?

Maurí­cio CA mauricio.antunes at gmail.com
Mon Oct 26 18:24:26 EDT 2009

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)?


More information about the Beginners mailing list