well-typed / hs-bindgen

Automatically generate Haskell bindings from C header files
20 stars 0 forks source link

Is typedef a type or a newtype or? #173

Open phadej opened 1 month ago

phadej commented 1 month ago

Should we translate typedefs as newtypes or types?

E.g.

typedef struct foo_s { ... } foo_t;

as

data Foo_s = ...
type Foo_t = Foo_s

or

data Foo_s = ...
newtype Foo_t = MkFooT Foo_s

or should this be (eventually configuble?)


What about anonymous structs and enums?

typedef struct { ... } foo_t;

currently we combine:

data Foo_t = ...

or should we still use type/newtype over a representation of anonymous structs/enums/unions?

edsko commented 4 weeks ago

As regards the first point, I think they should probably be newtypes, so that they can be given different class instances; see also discussion at https://github.com/well-typed/hs-bindgen/issues/168#issuecomment-2365065773 .