Well, "the above code" from alehander42 is Nim's usual way to go about object
variants and the code you don't like is the usual way to go about "methods" of
object variants. You might want to write `result = ...` instead of `return ...`.
proc addTwo(self: C): int =
case self.kind
of int: result = self.num + 2
of string: result = 10_000_000
else: {.fatal: "Meh, illegal case in addProc" .}
Run
- Re: How can we define a function that returns a type like a... Araq
- Re: How can we define a function that returns a type l... juancarlospaco
- Re: How can we define a function that returns a ty... moerm
- Re: How can we define a function that returns ... mrsekut
- Re: How can we define a function that retu... alehander42
- Re: How can we define a function that... mrsekut
- Re: How can we define a function ... mrsekut
- Re: How can we define a function ... moerm
- Re: How can we define a function ... mrsekut
- Re: How can we define a function ... alehander42
- Re: How can we define a function ... moerm
