In Scala, is it possible to "subtract" a type from a composed type like this one: "A with B with C" ?

-
Show this thread
-
-
Replying to @propensive @guizmaii
A with B is the type which represents the set union of the properties of A and the properties of B. We can construct A with B with A, and (by set theory) it's identical to A with B. So including A in the intersection again is idempotent. (1/2)
1 reply 0 retweets 0 likes -
Replying to @propensive @guizmaii
Therefore, the inverse operation of "intersecting with A" is not well-defined. In general, if you "remove" A from A with B, you're left with... A with B. (2/2)
1 reply 0 retweets 0 likes -
Replying to @propensive @guizmaii
That doesn't strike me as true, `A with B` represents the set intersection. `A | B` represents set union. You claim idempotency is why you can't have negation, but both intersection and union are idempotent!
2 replies 0 retweets 0 likes -
In terms of algebra, union and intersection types form a bounded distributive lattice. If we were to add negation, it would turn it into a boolean algebra. Certainly not impossible :)
2 replies 0 retweets 0 likes -
wouldn't you need a top element for a boolean algebra though? else there's no identity on intersect and some and some of the complement laws are tricky to do. what would such an element look like for types?
1 reply 0 retweets 1 like -
Yeah, exactly! Top is `Any` and bottom is `Nothing`. I talk about a lot of this in my most recent talk:https://youtu.be/DJyhWAwmGqE
1 reply 0 retweets 1 like -
This is where I get brain knots. In systems like typescript Any is essentially a type with all signatures (the analogue to untyped JS) as such it makes sense to treat it as the top type and it's fairly set-like. so i could imagine a concept of complements to work.
2 replies 0 retweets 0 likes
That sounds like the opposite of Scala. Nothing is the type which has all properties (or signatures)... Any has the fewest...
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.