Disjoint constraints for type parameters
See original GitHub issueI propose adding a new constraint T1, T2, …, Tn disjoint
for signifying type parameters T1
, T2
, …, Tn
are provably disjoint at compile-time with exactly the same algorithm as used for switch
cases.
It should enable us to write e. g.
function sumMap<Value1, Value2, Return1, Return2>(Value1|Value2 val, Return1(Value1) f1, Return2(Value2) f2)
given Value1, Value2 disjoint =>
switch (val)
case (is Value1) f1(val)
case (is Value2) f2(val);
or maybe more useful
Return|Error map…<Value, Error, Return>(Value|Error val, Return(Value) f)
given Value, Error disjoint =>
switch (val)
case (is Value) f(val)
case (is Error) val;
without disabling any warnings.
Maybe examples aren’t comprehensive enough, but it occurred to me this could be a nice feature and maybe even not hard to implement.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Chapter 7. Enhanced Entity-Relationship Modelling
There are three constraints that may apply to a specialization/generalization: membership constraints, disjoint constraints and completeness constraints.
Read more >Supertype/Subtype Disjointness Constraints - YouTube
Chapters. View all · Disjoint Rule Disjoint Rule Definition · Disjoint Rule Disjoint Rule Definition · Disjoint Rule Disjoint Rule Definition.
Read more >Enforcing Disjoint Unions with TypeScript Conditional Types
One of the more useful ones I've found is a “disjoint” type, which ensures that there are no elements in common between two...
Read more >disjoint and overlapping design constraints - Stack Overflow
The disjoint rule states an entity instance of a supertype can only be a member of one subtype. The overlap rule ...
Read more >Disjoint subtyping in SQL
Subtyping is disjoint if an instance of a type corresponds to at most one instance of a subtype. For example, we may have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about
given T1 & T2 is Nothing
?Actually, we could also write it the other way around, and reuse the existing syntax:
given Nothing satisfies T1 & T2
.This would allow for a future generalization like
given String satisfies T1 & T2
.i.e.