Zax Programming Language
Partial Types
The language has partial support for types. However, partial types are heavily restricted and caution must be used in creating partial types as they can inject variables, types, and functions inside existing declared type where the original type was not expecting any additional values to exist.
The primary motivation for partial is to support:
- extending the builtin context
___to include additional properties - add
finalfriend functions that should be present on othertypethus extend their usefulness in other scenarios - extending other context style types for usage as a catch all inside the context
While other use cases are supported, partial has some restrictions that must be adhered:
partialtypes can intercept construction after the main type is constructed and cannot prevent a type’s original constructor from being calledpartialtypes can intercept destruction before the main type is destructed and cannot prevent a type’s original destructor from being calledpartialtypes can interceptfinaloperators and functions by using the same prototype definition however extreme caution must be taken not to interfere with the argumentspartialtypes cannot intercept non-final operators and functions but can replace the functions post constructionpartialtypes are constructed in the order they are imported or declaredpartialtypes cannot rely on otherpartialtypes as having been initialized during the construction processpartialtypes can add new variables into to atypethat occupy memory on thetype
Some important concerns to consider:
partialtypes may accidentally inject names into types that could cause code misunderstandingspartialtypes may fatten the memory requirements for types where new variables are injected- the memory layout of a
typemay change which may cause any union expectations for atypeand it may cause undefined behaviors - the
ascasting operator for compatible types may error if anascasting destination type is ever extended to remain compatible with the additionalpartialtypes - functions calls cannot be intercepted from the base type (other than constructors)
- creating an instance of a
partialtype separate from the maintypeis not possible partialtypes may have name conflicts with otherpartialtypes and the compiler may error
Needless to repeat, use extreme caution with partial types. They are not meant to be the go-to tool in a programmer’s toolbox.
MyExtendedContext :: partial Context {
logCount : Integer
log final : ()(...) = {
// ...
++logCount
// ...
}
}
___.log("new function to extend context")