i'm writing a command-line framework (yes, I know Odin has one in the standard library, this is mostly a learning exercise for me :)) and i keep rubbing up against a really weird issue with parapoly and i was wondering if someone could give me some advice on how to handle it.
so basically, the idea for the framework side of things is that I have a Value struct that takes a type parameter of $T: typeid, which is fed into a procedure that parses a string into that type, essentially allowing any type to be defined as a potential value for a command argument. great! it looks like this:
Value :: struct($V: typeid) {
parse: proc(string) -> (V, bool),
}
i also have a struct called Switch which defines a "flag" in a command-line program. switches are never are by themselves, and should always rely on a Value (even -a with no (visible) argument is actually flipping a boolean variable, so it can be represented as consuming a Value anyway). i try to do this here:
Switch :: struct($T: typeid) {
long_forms: []string,
short_forms: []rune,
expects: ^Value(T),
default_val: T,
}
the reason it's ^Value(T) is because i planned on defining a set of "basic types" in the program, like file_type, that a user could easily reference by passing in a pointer to the initialized Value as like bind_value(&command_node, &cmd.file_type, &target_var) or something.
but, this above struct errors when compiled!
/home/flora/dev/cmd.odin(36:5) Error: Invalid parameter type
expects: ^Value(T), // :(
^~~~~~~~~~~~~~~~~~~~~^
every explanation i have for this only makes half-sense to me. like, i think it's doing this because it has to resolve the type parameters at compile-time, and so it fills it as Value(T), but because T on it's own isn't a type outside of the context of the type parameter, it's freaking out. but like... that doesn't actually make a whole lot of sense? if i put in int for $T, wouldn't it be ^Value(int)? @_@
the only problem is... i genuinely don't know how to design around this on a types level? i want to avoid loosening types that should be stricter (i.e. a parameter of typeid itself or god forbid just making it an any) as much as i can manage while writing this, because the types are the major thing upholding some form of "contract" for what can and cannot go into a command's arguments on the framework user's end
any advice on how i could avoid this problem would be appreciated ^^'