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

About C2HS generated ccall-s. #222

Open Magicloud opened 5 years ago

Magicloud commented 5 years ago

I think C2HS tends to ease the process of writing of FFI. And it provides a ^ in fun so I do not need to care about the naming. This is all cool.

But since C2HS generates all ccall-s with name'_ in the same module, I must either write a exporting list, which includes all the names I did not care, or show some weird things in IDE intelligent sense or doc by haddock.

Could C2HS also take care of this? I can think of two ways. One, provide a syntax for exporting list. Two, move all ccall-s into another module like STH.Internal.

deech commented 5 years ago

Is there a reason you can't make your C2HS modules Internal and only export the ones you care about in some public facing one?

I understand this isn't ideal but I'm not sure C2HS should be generating modules in your project tree.

To your first point, let me think about it. Do you have an export syntax in mind?

Magicloud commented 5 years ago

Sorry, I may not make myself clear. By using Internal, I meant to put the ccall-s in that, not C2HS wrappers. So the "normal" module would be clean that only contains the functions I defined with fun hook. Thus I do not need to bother with module exporting list.

For export syntax, I think a simple comma list satisfies. Something like

module Text (MyType, {#export#}) where

data MyType

{#fun c_fun#}

would exports Test.MyType, Text.c_fun.

deech commented 5 years ago

Did you mean {#export c_fun#} or does {#export#} mean to export all the C2HS generated functions?

Magicloud commented 5 years ago

I am thinking exporting all. If I need to write individual function names, it seems no difference than current manual way.