c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

About C2HS generated ccall-s.

Open Magicloud opened this issue 5 years ago • 4 comments

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.

Magicloud avatar Dec 15 '18 09:12 Magicloud

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?

deech avatar Dec 18 '18 16:12 deech

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.

Magicloud avatar Dec 19 '18 03:12 Magicloud

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

deech avatar Dec 19 '18 03:12 deech

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

Magicloud avatar Dec 19 '18 03:12 Magicloud