Hi,

I have a proc that needs to return many different and unrelated objects 
(structs) base on internal decisions. I tried model this using SUM return type 
(A or B). But this does not seem to work as I get a type mismatch on B path.

I know I can model SUM types using object hierarchies, but the types share 
nothing and the syntax is a bit heavy for my simple usecase

Do procs in Nim support returning SUM types? (A or B)

Ex:

type
    

A = object
    a_value:int
B = object
    b_value:int

Ret = A or B

proc test(arg:int):Ret =
    

if arg < 0:
    return A(a_value:arg)
else:
    return B(b_value:arg)

let a = test(10) let b = test(-5)

Reply via email to