Are there programming languages that allow you to do set arithmetic on types?
Posted
by
Will Brown
on Programmers
See other posts from Programmers
or by Will Brown
Published on 2012-11-21T00:29:03Z
Indexed on
2012/11/21
5:20 UTC
Read the original article
Hit count: 359
programming-languages
|type-systems
Out of curiosity, are there languages that allow you to do set arithmetic on types to create new types? Something like:
interface A {
void a();
void b();
}
interface B {
void b();
void c();
}
interface C = A & B; // has b()
interface D = A | B; // has a(), b() and c()
interface E = (A & B) ^ B; // has c()
I know that in some languages these ideas can be expressed (i.e., Java has List<Comparable & Serializable>
for the union of the interfaces) but I've never heard of a language that supports type arithmetic. Thanks!
© Programmers or respective owner