In Asymptote
types are specified when they are imported. The first executable line of any such
module must be of the form typedef import(<types>), where
<types> is a list of required type parameters. For instance,
typedef import(T, S, Number);
could be the first line of a module that requires three type parameters. The
remaining code in the module can then use T, S, and Number
as types.
To import such a module, one must specify the types to be used. For instance,
if the module above were named templatedModule, it could be accessed
for types string, int[], and real with the import
command
access templatedModule(T=string, S=int[], Number=real)
as templatedModule_string_int_real;
Note that this is actually an access command rather than an
import command, so a type, function, or variable A
defined in templatedModule.asy would need to be accessed
qualified as templatedModule_string_int_real.A.
Alternatively, the module could be imported via a command like
from templatedModule(T=string, S=int[], Number=real) access
Wrapper_Number as Wrapper_real,
operator ==;
This command would automatically rename Wrapper_Number to
Wrapper_real and would also allow the use of any operator ==
overloads defined in the module.
Further examples can be found in the tests/template subdirectory
of the Asymptote source directory.
Issues: Certain expected operators (such as
operator ==) may only be available for type arguments that are
builtin or defined in module plain.