Support for type synonyms
- Dominant language
- Haskell
- Stars
- 211
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Description
First of all, thank you for a great pre-processor!
I recently had a use case that can be simplified to this:
``` haskell
-- TypeSynonyms.chs
import Foreign.C
#include
{#fun fopen as ^ { `FilePath', `String' } -> `Ptr CFile' #}
```
If this is processed by c2hs (in my particular case v0.25.2), I get:
```
$ c2hs TypeSynonyms.chs
c2hs: Errors during expansion of binding hooks:
TypeSynonyms.chs:5: (column 20) [ERROR] >>> Missing "in" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: FilePath
C type : (Ptr CChar)
```
This can easily be solved by adding `withCString*` as in marshaller to the `FilePath` argument (or change `FilePath` to `String`, but I like the implicit documentation it brings), but in my real case I have a lot of functions accepting `FilePath`s. Hence, to keep it DRY, I tried to define a default marshaller for `FilePath`:
``` haskell
{#default in `FilePath' [char *] withCString* #}
```
but this didn't go as well as I'd hoped:
```
$ c2hs TypeSynonyms.chs
c2hs: Errors during expansion of binding hooks:
TypeSynonyms.chs:6: (column 20) [ERROR] >>> Missing "in" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: FilePath
C type : (Ptr CChar)
TypeSynonyms.chs:5: (column 3) [ERROR] >>> Internal type default error!
Something went wrong.
```
Perhaps there's already a simple solution that I have overlooked? Otherwise, I would like to make a vote for a new feature that solves this problem. Either something like my `#default` attempt or, in a perfect world, c2hs would see that `FilePath` is just a `String` and treat it as such.
Regards, Mattias
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.