3 ms·
> 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
by throway232lasdf 4y ago
> 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; };
- Smaug123 4y agoIn 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.)
- hither_shores 4y ago> 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
- jmull 4y agoThis is expressing the same value in two different ways. That's worse, not better.