An example in the wild that demonstrates this `fp-ts`'s explanation of how to do ADTs in TypeScript where you can see the comparison in PureScript is a one-liner (both data and polymorphic data): https://github.com/gcanti/fp-ts/blob/master/docs/guides/pure...
class Bar { tag="bar" as const; constructor(public value:string){} } class Baz { tag="baz" as const; constructor(public value:boolean){} } type Foo = Bar|Baz;
Also while pattern matching isn't an explicit thing in TS you get most benefits from compiler checked accesses that can recognize type-tests in your code and derive types and do property access checks.
Swift enums are really nice[0].
[0] https://littlegreenviper.com/miscellany/swiftwater/enums-wit...
I'm a fairly decent chap, and have nothing against you. Not sure why it's so important to you to begin our relationship with an attack. I suspect we have far more in common, than we do, differences.
I know that I sound like a demented old man, when I say that I miss the old days, when we all shared passions for the tech, and, even when we were in competition with each other, we tended to have respect for one another.
But those were also the days of the UseNet flamewars, so it wasn't all flowers and bunnies (and I was definitely a flame warrior).
In algebraic data types we have a sum (union) of a labeled cartesian products, and each product may have arbitrary number of values:
data MaybeInt = NoInt | AnInt Int
data MaybeItsPair = NoIntsPair | AnIntPair Int Int
The first constructor in both data types is a labeled (No...) product with empty number of value to apply cartesian product to.
The second constructor in both data types is a cartesian product: in first case an Int and in case a pair of Ints.
Of course you can have more involved data type:
data Expr = Void | Const Int | Var String | Bin BinOp Expr Expr | Un UnOp Expr
A label, two single value constructors and much more involved operations as well.
I haven't studied much theoretical computer science so I'd love to hear some good beginner resources on this stuff.
The number of variants of the AnIntPair construction is the number of distinct elements in the Int type, squared.
I used definition of algebraic data type in Haskell: http://wiki.haskell.org/Algebraic_data_type
Here’s an interesting little exploration: https://littlegreenviper.com/miscellany/swiftwater/writing-a...