That was cool, so I thought I'd try the same thing with +: ms:nim jim$ cat strfused.nim proc main() = var s: string template fused2{a = `&`(a,b)}(a:var string,b:string) = a.add(b) template fused3{a = `&`(a,b)}(a:var string,b:char) = a.add(b) template fused4{a = `+`(a,b)}(a:var string,b:string) = a.add(b) template fused5{a = `+`(a,b)}(a:var string,b:char) = a.add(b) for _ in 0..100_000_000: s = s + 'x' echo len(s) main() ms:nim jim$ nim c -d:danger strfused.nim Hint: used config file '/Users/jim/nim-1.2.1/config/nim.cfg' [Conf] Hint: system [Processing] Hint: widestrs [Processing] Hint: io [Processing] Hint: strfused [Processing] /Users/jim/nim/strfused.nim(9, 11) Error: type mismatch: got <string, char> but expected one of: proc `+`(x, y: float): float first type mismatch at position: 1 required type for x: float but expression 's' is of type: string proc `+`(x, y: float32): float32 first type mismatch at position: 1 required type for x: float32 but expression 's' is of type: string proc `+`(x, y: int): int first type mismatch at position: 1 required type for x: int but expression 's' is of type: string proc `+`(x, y: int16): int16 first type mismatch at position: 1 required type for x: int16 but expression 's' is of type: string proc `+`(x, y: int32): int32 first type mismatch at position: 1 required type for x: int32 but expression 's' is of type: string proc `+`(x, y: int64): int64 first type mismatch at position: 1 required type for x: int64 but expression 's' is of type: string proc `+`(x, y: int8): int8 first type mismatch at position: 1 required type for x: int8 but expression 's' is of type: string proc `+`(x, y: uint): uint first type mismatch at position: 1 required type for x: uint but expression 's' is of type: string proc `+`(x, y: uint16): uint16 first type mismatch at position: 1 required type for x: uint16 but expression 's' is of type: string proc `+`(x, y: uint32): uint32 first type mismatch at position: 1 required type for x: uint32 but expression 's' is of type: string proc `+`(x, y: uint64): uint64 first type mismatch at position: 1 required type for x: uint64 but expression 's' is of type: string proc `+`(x, y: uint8): uint8 first type mismatch at position: 1 required type for x: uint8 but expression 's' is of type: string proc `+`(x: float): float first type mismatch at position: 1 required type for x: float but expression 's' is of type: string proc `+`(x: float32): float32 first type mismatch at position: 1 required type for x: float32 but expression 's' is of type: string proc `+`(x: int): int first type mismatch at position: 1 required type for x: int but expression 's' is of type: string proc `+`(x: int16): int16 first type mismatch at position: 1 required type for x: int16 but expression 's' is of type: string proc `+`(x: int32): int32 first type mismatch at position: 1 required type for x: int32 but expression 's' is of type: string proc `+`(x: int64): int64 first type mismatch at position: 1 required type for x: int64 but expression 's' is of type: string proc `+`(x: int8): int8 first type mismatch at position: 1 required type for x: int8 but expression 's' is of type: string proc `+`[T](x, y: set[T]): set[T] first type mismatch at position: 1 required type for x: set[T] but expression 's' is of type: string expression: s + 'x' ms:nim jim$ Run
Seemed like a reasonable idea at the time...