I think this article makes the "sum" and "product" terms out to be very complicated, when in fact it's quite simple. If we have two enums enum Bool { True, False } enum Status { Waiting, Successful, Failed } We can combine them into a product type, like a tuple, or a sum type, like a union. type Product = (Bool, Status) type Sum = Bool | Status Now, we ask ourselves, what are the valid values of type Product? (True,…
This helps handle IO in pure functional languages because? Is it because functions can have more than 1 type?
Practical introduction to algebraic datatypes (ADTs) in TypeScript
21–23 of 23 posts
Re: Practical introduction to algebraic datatypes (ADTs) in TypeScript
#22Earlier quoted context omitted.
This helps handle IO in pure functional languages because? Is it because functions can have more than 1 type?
Can you elaborate what you mean by that? Support of sum and product types are used everywhere in typed functional languages and I don't know of any way they are exploited specifically in IO in a way that does not generalize to other domains.
Re: Practical introduction to algebraic datatypes (ADTs) in TypeScript
#23I think this article makes the "sum" and "product" terms out to be very complicated, when in fact it's quite simple. If we have two enums enum Bool { True, False } enum Status { Waiting, Successful, Failed } We can combine them into a product type, like a tuple, or a sum type, like a union. type Product = (Bool, Status) type Sum = Bool | Status Now, we ask ourselves, what are the valid values of type Product? (True,…
Indeed it would drive the point home if instead of simply mentioning product they referred to Cartesian product.
I guess sum types imply adding together two domain, but unless there's a subtlety then union would be clearer as well.