Re:The type system is a programmer's best friend
by throwawaymaths on Monday November 07, 2022 @11:28AM
(#33507982)
Two options:
1. Don't type units like that.
2. Allow the * operator to multiply a time-unitful value with an untimed scalar and disallow using it with two time-unitful values.
Presumably the requirement that * operands are the same is arbitrarily modifiable and go developers have control over what types operators take.
Re:The type system is a programmer's best friend
by morelisp on Monday November 07, 2022 @01:44PM
(#33510244)
1. Uh, ok. Might as well throw out the whole thread then?
2. A "time unit" is not a special type of value. You can construct arbitrary types of integers, and it is common to do so. `*` has no clue what a time is, just that it's "not an int" (for example).
It's slightly better than languages with no operator overloading nor newtypes at all (well, actually a lot better given other things you can use newtypes for) but without operator overloading using it just for units, with no other API machinery, is usually a bad idea.