The way to go:
type Addable = concept x, y
x + y
proc addit(a, b: Addable): auto =
return a + b
echo addit(12, 22.1) # -> 34.1
echo addit({1,3,5},{5,7}) # -> {1,3,5,7}
* * *
Yet you can explicitly convert arguments, this way you decide by yourself what
type is the result:
proc additF[T, U] (a: T, b: U): auto =
return a.float + b.float
proc additI[T, U] (a: T, b: U): auto =
return a.int + b.int
echo additF(12, 22.1) # -> 34.1
echo additI(12, 22.1) # -> 34
* * *
Yet you can use implicit conversion:
proc addit[T, U] (a: T, b: U): auto =
return a + b
converter x(x: int): float = x.float
echo addit(12, 22.1) # -> 34.1
But it can make the code's logic more messy.
* * *
Below "submit" button there's a hint on making your code sample
syntax-highlighted, makes reading easier.