Generics constrain with numbers

2020-09-10 Thread mratsim
It was probably made before SomeInteger existed some of the code there is very old

Generics constrain with numbers

2020-09-10 Thread archnim
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 Run Isn't it better (shorter) to write : `SomeOrdi

Generics constrain with numbers

2020-09-10 Thread archnim
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 = Run T1 is concerned by the constrain (uint8 | int8).

Generics constrain with numbers

2020-09-10 Thread archnim
Gracias very much ;-).

Generics constrain with numbers

2020-09-10 Thread mratsim
Use `SomeInteger`, `SomeFloat` or `SomeNumber`

Generics constrain with numbers

2020-09-10 Thread lscrd
This way: func myfunc(number: SomeInteger) = Run

Generics constrain with numbers

2020-09-10 Thread SolitudeSF
https://nim-lang.github.io/Nim/system.html#SomeInteger

Generics constrain with numbers

2020-09-10 Thread ElegantBeef
There is the `SomeNumber` which is `SomeFloat | SomeInt` which.. goes all the way up. From docs [here](https://nim-lang.org/docs/system.html#SomeNumber)

Generics constrain with numbers

2020-09-10 Thread archnim
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) = Run It could be longer, for example if I add floating types. Is there any way to shorten that code ?