3 ms·
I'm not a Haskell programmer, but I wish more languages had Newtypes. Most of the time I'm too lazy (or consider it too much boilerplate) to wrap strings in cl
by mikerichards 10y ago
I'm not a Haskell programmer, but I wish more languages had Newtypes.
Most of the time I'm too lazy (or consider it too much boilerplate) to wrap strings in classes. But on more than one occasion I've spent too much time tracking down a bug because I passed the wrong string to the wrong argument in a method.
- louthy 10y agoI implemented a newtype [1] system in C#. It's (obviously) not as robust as Haskell (relies on some runtime checks), and isn't as efficient (reflection and boxing for value types). But if type-safety is what you want, it's definitely an improvement over passing integers, strings, or other basic types around. [1] Implementation - https://github.com/louthy/language-ext/blob/master/LanguageExt.Core/NewType.cs https://github.com/louthy/language-ext/blob/master/LanguageE... [2] Unit tests / examples - https://github.com/louthy/language-ext/blob/master/LanguageExt.Tests/NewTypeTests.cs https://github.com/louthy/language-ext/blob/master/LanguageE... [3] The request that led to the feature - https://github.com/louthy/language-ext/issues/95 https://github.com/louthy/language-ext/issues/95