There are many possible approaches. I think that rather simple
approach is most useful. Namely, categories define abstact
interface, that is set of available operations (including
their signatures). There is interface inheritance, done
via "Join": given category may inherit from other categories,
then it posseses all properties of those categories. In
effect there is inheritance DAG, category directly inherits
from categories mentioned in its definition (that is from its
parents), but also inherits all categories and signatures
from its parents. "has" for named categories is explained
in FriCAS book: this is decided by assertion, that is category
'A has B' if and only if B appears in inheritance chain.
There are some twists. The above rule is related to "name
equivalence" of types. In FriCAS there are also unnamed
categories which use "structural equivalence". Unnamed
category U may be viewed as set of categories and signatures.
Category A has unnamed category U if and only if it has
all categories and signatures appearing in definition of U.
Concerning domains, one can associate a category with each
domain. For domain D you can think of it as 'typeOf(D)'.
Internally, part of domain definition before '== add ...'
part is compiled as a category, this category determines
interface of the domain.
The above is actually quite close to handling of types in
typical programming languages. In FriCAS interesting part
is that types have parameters. Parameters alone create
only modest complication, basically to answer 'A has B' you
need to be able to determine if any ancestor of A is equal
to B. "Name equivalence" means that we need to compare names
of constructors, if names are different then clearly we do not
have equality. FriCAS has no overloading for constructors,
so if names match, then also number of arguments matches and
to decide equality we need to compare arguments.
In FriCAS some exports are conditional. That actually requires
answer to some tricky questions. Consider:
A : Category == with
if % has B then C
if % has C then B
What we get asking 'A has B'? I did not check if this is implemented
correctly, but official answer is 'no'. Similar things appeared
earlier trying to define semantics of programming languages via
recursive equations and the approach which works reasonably well
is to take "minimal fixpoint". There is restriction: a cycle
of dependences can not contain negation. So
A : Category == with
if not(% has B) then C
if % has C then B
is illegal.
--
Waldek Hebisch