3 ms·
What do you mean by "strict typing of its index"?
by bheadmaster 2mo ago
What do you mean by "strict typing of its index"?
- dwattttt 2mo agoI expect it's referring to the newtype pattern; you don't want to accidentally add inches to cm, so if you have to handle both of them a lot, you make a single field struct Inches and one for Cm. For containers, you can do this to make it a type error to index the container with anything other than the newtype you made. In some languages you can replace/implement the indexing operation a[i] with your new type, so the code looks the same as usual, but gets the benefit of preventing the wrong 'integer' from being used.