Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
language:impl [2023/04/09 22:06] – [Overrides] rajitlanguage:impl [2026/08/05 15:30] (current) – [Variant overrides] rajit
Line 264: Line 264:
 </code> </code>
 The ''+'' indicates that these are //extra// template parameter(s) that should be added to the existing ones that have already been specified for the instance ''id'' in the original type definition. The ''+'' indicates that these are //extra// template parameter(s) that should be added to the existing ones that have already been specified for the instance ''id'' in the original type definition.
 +
 +
 +==== Variant overrides ====
 +
 +If a process has non-strict template parameters, then variants of the process with different non-strict parameter values may need different overrides. While this is straightforward for simple instances, if an array contains a collection of process variants, then this creates a challenge in declaring an override.
 +
 +To support this, consider the process below:
 +<code act>
 +template<pint W | pint VAL>
 +defproc addbuf(chan?(int<W>) L; chan!(int<W>) R)
 +{
 +   int<W> x;
 +   chp {
 +      *[ L?x; R!(x+VAL) ]
 +   }
 +}
 +</code>
 +
 +If we have different implementations of ''addbuf'' depending on the value of ''V'', we can describe this as follows:
 +<code act>
 +defproc impl_addbuf <: addbuf()
 ++{ 
 +     ... any overrides for ports here ...
 +}
 +
 +    /* the default implementation */      
 +    ...
 +}
 +| addbuf<W,4> => {
 +   /* different implementation when the non-strict parameter has value 4 */
 +}
 +| addbuf<W,8> => {
 +   /* different implementation when the non-strict parameter has value 8 */
 +}
 +</code>   
 +
 +This variant override syntax permits variations of the implementation relation based on the specific values of the non-strict template parameters.