Skip to content

Type Arguments

Xanderplayz16 edited this page Jun 30, 2022 · 7 revisions

In cish, type arguments can be used both for procedures, and records/structures. Keep in mind, however, that type arguments are only applicable for the scope in which they are defined - that also means that one cannot access a type argument defined in a scope other than the current one, including previous defined ones, or relevant scopes that encapsulate the current scope.

As of the latest version of cish, type parameters can only be used as generics - there is no associated functionality.

Defining Type Params

Generally speaking, generic type parameters can be defined using the following syntax:

<param1, another_param, something_more>

It doesn't necessarily have to be three - in procedures, type parameters are limited by the maximum size of a type id (max 256 type params), and in records where the type arguments are limited by the amount of maximum sub-types/type argus(max 100 type args). Note: Generally speaking, keep all types of arguments/parameters under 100.

In Procedures

Type arguments are specified right before value arguments while declaring procedures. As you recall, procedures are declared like:

global readonly auto myproc = proc(int arg1, char arg2) {
  //... do shit here
}

To specify generic type parameters, do this:

global readonly auto procwithgenerics = proc<typearg1, typearg2>(array<typearg1> elements, typearg2 second_arg) {
  //... do more stuff
}

Note that if procwithgenerics were to typecheck against another procedure, not only would it need to have the same amount of value parameters, but it has to have the same number parameters. Also note that typearg1 will not be type compatible(it will fail in a typecheck) with any typearg2. Generics are automatically assumed to have no predefined characteristics or traits whatsoever, and can only be type-compatible amongst other generics of the same type.

To pass type arguments into type parameters, you'd have to pass it in using < and > to to encapsulate a few type's as arguments before declaring value arguments. Take this for example:

procwithgenerics<int, char>(myIntArray, myStupidChar);

Also, if generics are applicable in the current scope generics can also be passed as type arguments. Keep in mind that cish type arguments are actually non-deterministic.

In Records

Please refer to this wiki article that details how type arguments work with records. Keep in mind, that the rules stated here all apply in the same manner.

Clone this wiki locally