haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] getPtrSize works, but is annoying

Subject: Re: [Haskell-cafe] getPtrSize works, but is annoying
From: Luke Palmer
Date: Fri, 18 Dec 2009 12:28:19 -0700
On Fri, Dec 18, 2009 at 12:20 PM, Gregory Crosswhite
<gcross@xxxxxxxxxxxxxxxxxxx> 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)
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>