3 ms·
> In my javascript (well, typescript) version, I'm critiquing the implementation shown in the blog, not your hypothetical implementation in typescript that I'v
by leshow 7y ago
> In my javascript (well, typescript) version,
I'm critiquing the implementation shown in the blog, not your hypothetical implementation in typescript that I've never seen.
> What pattern matching do you need for an either type?
In nominal type systems like Rust/Haskell/F# you want to be able to match on the constructor. In typescript where '|' means something slightly different you need to fake a type constructor by adding a type: "variantname" property
> I deny it. IMO you can create a perfectly usable Either Type in any language that supports classes, objects and generics (well, maybe not C++).
Javascript doesn't support those things.
- lacampbell 7y agoI'm critiquing the implementation shown in the blog, not your hypothetical implementation in typescript that I've never seen. That was not what you originally wrote: The fact is that it's forcing a concept that can't be expressed in the language properly. Your claim was that it cannot be expressed in the language properly, and I am disagreeing. In nominal type systems like Rust/Haskell/F# you want to be able to match on the constructor. In typescript where '|' means something slightly different you need to fake a type constructor by adding a type: "variantname" property You didn't answer the question, what useful pattern matching can you do with Either/Option? Give me pseudocode even. Javascript doesn't support those things. A few jsdoc comments and tsc command, and hey presto - it does.