Hello world. Here's the first line of my function:
func myfunc[T: int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uin64 ](number: T) =
It could be longer, for example if I add floating types. Is there any way to shorten that code ?This way:
func myfunc(number: SomeInteger) =
I did few tests to understand better generics syntax. This is a cool observation I made (Just for beginners like me who don't know it): If I write :
func myfunc[T1, T2: uint8| int8](number1: T1, number2: T2): bool =
T1 is concerned by the constrain (uint8 | int8). It means that T1 too can only be an uint8 or an int8. To break that behavior (called type propagation), just replace the comma between T1 and T2 by a semicolon.This is something I don't understand : The implementation of SomeOrdinal in /lib/system/basic_types.nim, on line 32 is the following:
SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint|uint8|uint16|uint32|uint64
Isn't it better (shorter) to write : SomeOrdinal* = SomeInteger | bool | enum ?