haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
199 stars 50 forks source link

In what case would c2hs import Foreign.Ptr? #218

Open Magicloud opened 5 years ago

Magicloud commented 5 years ago

I have two pointers defined in exactly the same way. And two modules contains fun definitions for each pointer. One of them built well. The other complains on unknown type Ptr. Apparently, in the second .hs file, a few imports are missing. I could not figure out what caused the difference.

error message

Not in scope: type constructor or class ‘C2HSImp.Ptr’
Neither ‘Foreign.C.Types’ nor ‘Foreign.ForeignPtr’ exports ‘Ptr’.

pointer definition {#pointer *c_typedef as Typedef foreign finalizer typedef_destroy newtype#}

broken .hs generated

import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import MyTypes

working .hs generated

import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import MyTypes
import Foreign -- I have this in .chs
Magicloud commented 5 years ago

I also got another issue that Foreign.Marshal is not imported when I need with and alloca. And Foreign.Storable when I need peek.