3 ms·
Perhaps it's because I'm not a haskeller but I'm not sure if I'm sold on encoding this into the type system. In go (and other languages for example), you would
by b_e_n_t_o_n 1y ago
Perhaps it's because I'm not a haskeller but I'm not sure if I'm sold on encoding this into the type system. In go (and other languages for example), you would simply use a struct with a hidden Int, and receiver methods for construction/modification/access. I'm not sure I see the benefit of the type ceremony around it.
- the_af 1y agoIsn't the whole article a discussion of the kind of guarantees such an approach (which can also be done in Haskell) cannot provide?
- b_e_n_t_o_n 1y agoRight, I'm just unsure how valuable those guarantees really are. Especially if I'm extracting an Int out of the type to interface with other code.
- the_af 1y ago> Especially if I'm extracting an Int out of the type to interface with other code. Why would you do this? As soon as you go "outside" the type you lose typechecker guarantees. The whole point of the article is showing where the compiler can tell you when you're writing code that fails to consider some cases, and how use of `newtype` loses some of these guarantees.
- b_e_n_t_o_n 1y agoI don't think I'm gonna find a library that supports my OneToFive type.
- the_af 1y agoYour type comes with its own library, and the compiler makes sure you're not misusing it by failing to consider a possible case. If you need to use your OneToFive someplace that actually wants an integer, that happens at the boundary. Everything else is safer.
- cryptonector 1y ago> you would simply use a struct with a hidden In such languages that's the equivalent of a newtype in Haskell.