CPSC 103 Lecture 2:
CPSC 103 verified notes
2/26View all
Document Summary
Templates are the core structure that we know a function must have, independent of the details of its implementation. In many cases the template for a function is determined by the type of data the function consumes. We refer to these as data driven templates. The recipe below can be used to produce a data driven template for any data type definition. For a given type typename the data driven template is: def fn_for_type_name(x: typename) -> : body. Where x is an appropriately chosen parameter name (often the initials of the type name) and the body is determined according to the table below. To use the table, start with the type of the parameter, i. e. typename, and select the row of the table that matches that type. The first row matches only primitive types, the later rows match parts of data type definitions.