[Haskell-cafe] getPtrSize works, but is annoying

Luke Palmer lrpalmer at gmail.com
Fri Dec 18 14:28:19 EST 2009


On Fri, Dec 18, 2009 at 12:20 PM, Gregory Crosswhite
<gcross at phys.washington.edu> wrote:
> Ugh, I figured out how to write code to do what I wanted, but it seems like an ugly solution:
>
>        getPtrSize :: Ptr a -> Int
>        getPtrSize = getFrom dummy
>          where
>                getFrom :: a -> Ptr a -> Int
>                getFrom dummy _ = sizeOf dummy

With -XScopedTypeVariables:

getPtrSize :: forall a. Ptr a -> Int
getPtrSize p = sizeOf (undefined :: a)


More information about the Haskell-Cafe mailing list