Operators as parameters to composite operators

A composite operator encapsulates a subgraph and some of the operators in that subgraph can be given to the composite operator as parameters at the time of invocation.

Thus, composite operators can act as generic graph stencils, which are useful for implementing high-level distributed well-structured computation. The following code is a parametric version of the composite operator M.

composite M (output K, L; input G, H) {
  param operator $Q; //operator (primitive or composite)
  graph stream<int32 x> I =  Functor(G) { /*..O..*/ }
        stream<int32 x> J =  Functor(H) { /*..P..*/ }
        stream<int32 x> K = $Q(I; J)    { }
        stream<int32 x> L =  Functor(J) { /*..R..*/ }
}
composite Main {
  graph stream<int32 x> A = Beacon() {}
        stream<int32 x> B = Beacon() {}
        (stream<int32 x> C; stream<int32 x> D) = M(A; B) { param Q: S; }
        (stream<int32 x> E; stream<int32 x> F) = M(A; B) { param Q: T; }
}

Identifiers of formal parameters of composite operators start with a dollar ($) sign. This figure illustrates how the composite operator and its parameter get expanded. The first expansion, on the top, replaces the placeholder parameter $Q by the actual operator S. The second expansion, on the bottom, replaces the parameter $Q by the actual operator T.

Figure 1. Composite operator parameter example

This figure is described in the surrounding text.