If all you want is to prevent the equality operator (==), you can do: type I1 = distinct uint32 I2 = distinct uint32 converter toU32 (value: I1): uint32 = value.uint32 converter toU32 (value: I2): uint32 = value.uint32 proc `==`(i1: I1, i2: I2): bool {.error: "Thou shall not compare types I1 and I2".} var v: uint32 = 1 v1: I1 = 1.I1 v2: I2 = 1.I2 if (v1 == v): # works echo "1: true" if (v2 == v): # works echo "2: true" if (v1 == v2): # compile error! echo "3: true" Run
- Re: Not-so-distinct types cdome
- Re: Not-so-distinct types Manny8888
- Re: Not-so-distinct types Manny8888
- Re: Not-so-distinct types Stefan_Salewski
- Re: Not-so-distinct types Manny8888
- Re: Not-so-distinct types Stefan_Salewski
- Re: Not-so-distinct types mashingan
- Re: Not-so-distinct types Manny8888
- Re: Not-so-distinct types mashingan
- Re: Not-so-distinct types Manny8888
- Re: Not-so-distinct types boia01
- Re: Not-so-distinct types mratsim
- Re: Not-so-distinct types Manny8888