[Haskell-beginners] which typefor this FFI call

Sylvain Henry sylvain at haskus.fr
Wed Jun 28 14:24:49 UTC 2017


On 28/06/2017 15:27, PICCA Frederic-Emmanuel wrote:
> my question is, when I write this
>
>    let opData = InOut $ castStablePtrToPtr statePtr
>
> I have InOut (Ptr ()) is it possible to have somthing more like InOut (Ptr a) instead ?
>

Yes it's strange that `castStablePtrToPtr` returns `Ptr ()` instead of 
`Ptr a`. You can use `castPtr` to get the type back:

   let opData = InOut $ castPtr $ castStablePtrToPtr statePtr


https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Foreign-Ptr.html#v:castPtr

-Sylvain


More information about the Beginners mailing list