| The ultimate |
We plan to improve the current
Concretely speaking,
Let us explain these ideas in a bit more detail.
In classical type systems, each variable x has a type
T (written x:T). In
In other words, if x:TU in a given context, then x may both be used as an object of type T or as an object of type U, i.e. x has been overloaded, or the result of an ambiguous expression. The following logical type constructors are currently implemented in the type system (although only and are currently available in the interpreter):
In the future, we also plan to add conditional types RT, with x:RT⇔(R⇒x:T). The relations R should be defined using first order logic axioms (and possibly refer to predicate routines). For instance, this would permit to use types like T,Ring(T)T→T.
The advantage of logical supertypes is that it is possible to define functions which are only valid under very precise circumstances, which are modelized using first order logic. This makes the system very extensible and customizable.
Indeed, assume for instance that you have functions f and g, where g depends on f and where f is valid under certain circumstances. Then it may be that someone makes a new implementation of f under another circumstance. Then it becomes automatically possible to apply g in this new circumstance.
It may also be that the original implementation of f is
valid under very broad hypothesis, but also very unefficient. Then a
new user may reimplement f under more particular hypothesis
later. Here
Another major advantange of the logical supertype approach is that it
allows for less hierarchic design of big projects. For example,
consider the problem where you have trees with n types of
possible nodes and that you need to define k types of
actions on trees which depend on the nodes, but where many
implementations can be grouped on either node type or action type. In
Of course, it is nice to design a very powerful type system, but it is also nice if one can implement it. In the most general setting of first order logic, this is quite hopeless. Nevertheless, only a tiny part of the first order logic is used in practice, even though it may be hard to indentify this part. Our approach is to progressively extend the strength of the implementation of the type system and accept the fact that it will not do everything. This should make certain types of uses perfectly reliable, but it will remain up to the user not to abuse the type system.
In order to make this philosophy fully functional, it is nice to make
the type system as independent as possible from the rest of the
language, so that it might actually be carried out by a dedicated
systeem, like a theorem proving system. In
At the moment, the type system is able to handle pure predicate logic (restricted to and ) well. It can also deal with types of the form
in a systematic way, and conjunctions of such types. Many easy other types can also be dealt with, though not systematically. A current limitation is that when you have a method
and an implicit converter T↝U, then f can not yet be applied to (T,U).
The precise semantics of logical supertypes is still under
development. One has to decide in particular if one wants to restrict
the application of quantifiers to atomic supertypes (i.e.
If one may take X = TU, then, using the convertions T↝TU and U↝TU, it becomes possible to applie f to (T,U) since this is the case for all T and U, we obtain an implicit converter
| X,(X,X)→()↝T,U,(T,U)→() | (1) |
Here one hits the limitations of the approach of not requiring any
additional information on types, like a category in
then it is not really necessary to know the type of X, since it is very likely that the user will only apply it in the case when there is a multiplication defined on X. However, if one has multiplications on T and U, then it is highly unlikely to have a multiplication on TU, so the implicit conversion (?) is generally abusive.