|
|
|
|
|
by meetups323
1940 days ago
|
|
I'm not sure what you mean by `Person (Compose Maybe Maybe)`? Is that a person with values you have to unwrap twice to use? That's not really a thing in TS, it either is undefined or isn't. But if you need to shoehorn Haskell into TS for whatever reason I guess you could do something like: type Maybe<T> = {hasValue: false} | {hasValue: true, value: T}
type Shoehorn<T> = { [P in keyof T]-?: Maybe<Maybe<P>> }
|
|
`Compose Maybe Maybe T` (equivalently `Maybe (Maybe T))`), has N + 2 values (where N in the probably-infinite number of values T has):
. N values consisting of a T
. 2 different values that do not include a T
It's also equivalent (via 1 + (1 + N) = (1 + 1) + N) to `Either Bool T`.
And yes, `Person f` contains values of type `f Whatever`.
> it either is undefined or isn't.
Values are never undefined. They might be defined as a object that's called "undefined", but that is a specific, defined, value. And, apropos of the above, it's a single value, out of the two distinct non-T values being represented. Which is part of why the example at https://news.ycombinator.com/item?id=26277598 looks horrible - it seems like it would confuse the two different non-T values with each other if `Person f` includes a `f (Maybe T)`.
Edit: actually, clarified the previous comment a bit, too.