[Haskell-cafe] sizeOf on a type

wren ng thornton wren at freegeek.org
Sat Dec 19 19:21:57 EST 2009

Sean Leather wrote:
>> 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?
> Lexically scoped type variables:
> http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html#scoped-type-variables

And if you require H98+FFI only, you can also use the following:

     ptrSizeOf = sizeOf . asTypeOf undefined . unsafePerformIO . peek

The asTypeOf function is the H98 way of handling many scoped type 
variable issues. It never evaluates its second argument so the 
unsafePerformIO is perfectly safe since the peek will never be evaluated 
either (and, heck, the whole argument to sizeOf won't be evaluated either).

Live well,

More information about the Haskell-Cafe mailing list