3 ms·
(Using a thin wrapper like this to add safety is called the newtype pattern, if anyone wants to know.)
by maxbond 1y ago
(Using a thin wrapper like this to add safety is called the newtype pattern, if anyone wants to know.)
- tetha 1y agoI was curious how this would look in C, and I found this article[1] how this could look in C, apparently with very little overhead. And as I just saw, Python 3.10 also introduced a NewType[2] wrapper. I'll have to see how that feels to handle. 1: https://blog.nelhage.com/2010/10/using-haskells-newtype-in-c/ https://blog.nelhage.com/2010/10/using-haskells-newtype-in-c... 2: https://typing.python.org/en/latest/spec/aliases.html#newtype https://typing.python.org/en/latest/spec/aliases.html#newtyp...
- masklinn 1y agoPython’s NewType is, confusingly, a very different thing: it’s a compile-time-only subtype of the original, rather than a Haskell-style newtype (which is an entirely separate type from its source).
- mrkeen 1y agoI've re-read the article again since getting a bunch of up and down votes across the comment section, and I think you've chosen a better name for this article than PdV. It really is just about using newtype wrappers.