Hacker News new | ask | show | jobs
by mikerichards 3662 days 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.

1 comments

I 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/LanguageE...

[2] Unit tests / examples - 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