0
$\begingroup$

Is there a known algebraic structure over set of Types (however they are defined) which is equipped with:

  1. commutative and associative product operation for building product types from simpler types, and
  2. relation of inheritance, ie. relation which shows that certain product types share factors (are build up from common simpler types).

Cartesian product is not practical as the operation (1) because it is not commutative and associative (though results are isomorphic).


Detailed explanation

I'm interested in modeling notions of class and structure from computer programming in algebraic manner - meaning to introduce a set of rules which can be used to calculate with classes and structures.

Let's define following structures in $C$:

struct PhysicalCharacteristics {
   height: int;
   width: int;
}

struct Human {
   height: int;
   width: int;
   name: string;
   age: double;
}

struct Human2 {
   physique: PhysicalCharacteristics;
   name: string;
   age: double;
}

I am looking for an algebra which would allow me to express statements like these: \begin{eqnarray} \text{PhysicalCharacteristics}&=&\text{int}^{\{\text{width}\}} \times \text{int}^{\{\text{height}\}}\\ \text{Human}&=&\text{int}^{\{\text{width}\}} \times \text{int}^{\{\text{height}\}} \times \text{string}^{\{\text{name}\}} \times \text{double}^{\{\text{age}\}}\\ &=&\text{PhysicalCharacteristics} \times \text{string}^{\{\text{name}\}} \times \text{double}^{\{\text{age}\}}\\ \text{Human2}&=& \text{PhysicalCharacteristics}^{\{\text{physique}\}} \times \text{string}^{\{\text{name}\}} \times \text{double}^{\{\text{name}\}}\\ &=&(\text{int}^{\{\text{width}\}} \times \text{int}^{\{\text{height}\}})^{\{\text{physique}\}} \times \text{string}^{\{\text{name}\}} \times \text{double}^{\{\text{name}\}} \end{eqnarray}

and where $\times$ is commutative and associative and where we can formally establish a notion that type $\text{PhysicalCharacteristics}$ is a subtype of $\text{Human}$.

$\endgroup$
3
  • 1
    $\begingroup$ You'd be better off asking on cstheory.stackexchange.com $\endgroup$ Commented Aug 28, 2023 at 22:18
  • 1
    $\begingroup$ What is $\mathrm{int}^{\lbrace\mathrm{cow}\rbrace} \times \mathrm{bool}^{\lbrace\mathrm{cow}\rbrace}$ supposed to mean? $\endgroup$ Commented Aug 28, 2023 at 22:42
  • $\begingroup$ It would essentially mean that we modified type int and bool by associating label "cow" to it. This labeling would be preserved through product operation. Thanks for suggestion about cstheory. $\endgroup$
    – 000 000
    Commented Sep 3, 2023 at 9:00

0

You must log in to answer this question.

Browse other questions tagged .