@c "cast2hac/templates.texi"
@c $Id: templates.texi,v 1.2 2007/10/29 01:02:37 fang Exp $

@node Templates
@chapter Templates
@cindex templates

@menu
* Template Basics::
* Template Instantiations::
* Default Parameters::
* Relaxed Templates::
@end menu

@c ----------------------------------------------------------------------------
@node Template Basics
@section Template Basics
@cindex templates

@CAST{} supported parameterized definitions and types, also known as templates.
@HAC{} supports templates using C++-like template syntax.  
Templates are useful for defining a family types with 
highly regular differences.  
Such generalizations often occur in definitions whose 
port sizes or implementations vary enumerably or trivially.  
The most notable differences from @CAST{} templates and @HAC{} templates
is the use of angle brackets around template arguments 
and parameter declarations, and the grammatic location of the 
template signature@footnote{This originates from C++ template syntax.}.  

In @CAST{}, a parameterized definition might look like this:

@example
define foo(int N) (node[N] x) @{ @}
@end example

The equivalent definition in @HAC{} would be:

@example
template <pint N>
defproc foo (bool x[N]) @{ @}
@end example

@CAST{} and @HAC{} alike support parameter-dependent template parameters.

@example
define array()(int N, D[N]) @{ @}
@end example

@noindent
would be written in @HAC{} as:

@example
template <pint N, D[N]>
defproc array() @{ @}
@end example

Definitions are not the only templatable entities.  
@c Section~\ref{sec:typedefs:templates} 
@ref{Typedef Templates},
discusses how typedefs 
can be templated in @HAC{}.  

@c ----------------------------------------------------------------------------
@node Template Instantiations
@section Template Instantiations
@cindex template instantiation

In @CAST{}, templates were instantiated by passing parameter values
in parentheses, e.g. @samp{e1of(2)}.
In @HAC{}, template parameters are passed in angle brackets, e.g.
@samp{e1of<2>}.  

@c ----------------------------------------------------------------------------
@node Default Parameters
@section Default Parameters
@cindex default parameters
@cindex template default values

See the @HAC{} Language Specification.

@c ----------------------------------------------------------------------------
@node Relaxed Templates
@section Relaxed Templates
@cindex relaxed templates
@cindex relaxed parameters

See the corresponding chapter of the @HAC{} Language Specification
document for more details.  
TODO: texinfo document link.

Relaxed templates allow certain parameters of a type template
to @emph{vary} within an aggregate collection (with the same base name).  

Update: this has been implemented in the compiler.


