News for hackers. Stuff that matters.
Re:The type system is a programmer's best friend by throway232lasdf on Saturday November 05, 2022 @11:05AM (#33482153)
> Why is it better to have two email types, VerifiedEmail and UnverifiedEmail vs. one Email type with an "isVerified" field?

You obviously have no idea what a type is.

    type VerifiedEmail = { email: string; is_verified: true; };

    type UnverifiedEmail = { email: string; is_verified: false; };
Re:The type system is a programmer's best friend by Smaug123 on Saturday November 05, 2022 @12:24PM (#33482942)
In fairness this takes an unusually strong type system to express, doesn't it? Typescript can do it, but I don't think e.g. Haskell98 can do it out of the box in an analogous way? (Of course, it's hard to prove a negative and I'm not super familiar with Haskell, but my evidence is that I'm pretty certain F# can't.)
Re:The type system is a programmer's best friend by hither_shores on Saturday November 05, 2022 @01:29PM (#33483559)
> but I don't think e.g. Haskell98 can do it out of the box in an analogous way?

This is basically the runtime representation of `data Email = Verified { email :: string } | Unverified { email :: string }`, but promoting `Verified` and `Unverified` to type level requires an extension:

    data Email (verified :: bool) where
         Verified :: string -> Email true
         Unverified :: string -> Email false
Re:The type system is a programmer's best friend by jmull on Saturday November 05, 2022 @03:44PM (#33484879)
This is expressing the same value in two different ways. That's worse, not better.