archives

Signatures involving multimethods in programming language Theme-D

Theme-D implements signatures involving multimethods. They resemble interfaces
with explicit definitions in Julia, see this.

The following algorithm is used to determine if a non-signature type is a
subtype of a signature:
---
A non-signature t1 is a subtype of signature t2 iff for each specifier
s = (proc-name args result attributes ) in the complete specifier list of t2
there exists a procedure (simple, parametrized, or generic) with name proc-name
so that the class of this procedure is a subtype
of the abstract procedure type (:procedure args result attributes ) where the
keyword 'this' has been substituted with type t1.
---

With a normal generic procedure the check is done in the lexical environment of
the signature. With a virtual generic procedure the check is done in the lexical
environment of the check.

The following algorithm is used to dispatch a procedure call where some of the
argument types are signatures:
---
If the arguments contain free type variables the type is checked runtime.
Otherwise:
1. For each signature in the argument list types starting from left to right
substitute keyword this by the signature itself in all the procedure specifiers
referring to the same procedure as the procedure to be called. If the
call argument type list is a subtype of the substituted procedure specifier
argument list stop the both iterations.
2. If a matching procedure specifier was found take the result type of the call
from the specifier and dispatch the procedure call dynamically. Otherwise:
(a) If the procedure was encountered in some of the signatures report a
type mismatch error.
(b) Otherwise handle the procedure call as a normal procedure call.
---

I'm considering adding the following check into the language translator:

---
If some signatures contains a procedure specifier no procedure definition
(simple, parametric or generic) may contain a signature in the argument
position(s) having keyword 'this' in the specifier.
---

For an example use case implementing associations (e.g. association lists
or hash tables) with signatures see assoc-test.thp.

Note that a signature is computed from a parametrized signature by substituting
the type parameters with some types.

See this for programming language Theme-D.