Hacker News new | ask | show | jobs
by frogulis 1820 days ago
I think the article goes a little further than what you describe -- it would have you use a strong type that cannot represent illegal values.

There's a follow-up article by the same author (that I unfortunately can't find), in which she explains this point.

As an example, returning a NonZero newtype over Int is not as type safe as using an ADT that lacks a zero value altogether. Using a NonEmpty newtype over List is not as type safe as using the NonEmpty ADT that has an element as part of its structure.

Basically newtype still has use, but it is not as airtight as a well-designed ADT.

1 comments

> There's a follow-up article by the same author (that I unfortunately can't find), in which she explains this point.

I think this is it: https://lexi-lambda.github.io/blog/2020/11/01/names-are-not-...