[Haskell-cafe] sizeOf on a type

Gregory Crosswhite gcross at phys.washington.edu
Fri Dec 18 14:16:42 EST 2009


Hey everyone,

I would like to write a routine like

	nextPtr :: Storable a => Ptr a -> Ptr a
	nextPtr = (`plusPtr` sizeOf (undefined :: a))

which increments a pointer by the correct amount, but GHC complains that the type variable "a" is ambiguous.  I can see what's going on:  it can't tell that the "a" I am writing there is the same "a" that's in the type specification, but is there any way that I can make it identify "a" with the "a" in the specification for nextPtr?

Cheers,
Greg



More information about the Haskell-Cafe mailing list