I’m transpiling to C, and want to differ between value types (types that can be safely copied by C automatically) and reference types. So, imagine in the AST I have
type typ =
| Int
| Float
| Struct
A struct can be both a value type and a reference type. Is it advised to add a type parameter? Even if it leads to redundancy in some cases? Or is it better to add a separate struct type?
type typ =
| Int
| Float
| Struct_value
| Struct_reference
Or
type kind =
| Ref
| Val
type typ =
| Int
| Float
| Struct of kind
Or even
type 'a typ =
| Int
| Float
| Struct of 'a
Maybe the of kind
is better if other types also can be both val
or ref
? But you don’t have different types of kinds…
Then you have
let type_is_val = function
| Int | Float | Struct Val -> true
| _ -> false