I would like to do something like the following:
type Encodable = int | string
type Encoded = object
...
proc encode(i: int): Encoded = ...
proc encode(s: string): Encoded = ...
proc encode(l: seq[Encodable]): Encoded = ...
This seems to compile fine, however I still cannot do something like:
let encoded = encode(@[1, "a"])
because heterogeneous sequences are not supported. In this scenario, shouldn't the common typeclass "unify" the int and string resulting in a homogenous sequence?
I know I could use a variant type here, but I would prefer to keep the interface as simple as possible.
Is there a suggested workaround for this? Maybe a macro is necessary?