Contrary to [[Max (software)|Max-like]] [[visual programming languages]] where the user does manual connections, FAUST primitives are assembled in [[block diagramsdiagram]]s by using a set of high-level block diagram composition operations. You can think of these[[Function composition operators as a generalization of the mathematical function |composition]] operatoroperations.
[[File:Faust-simple-block-diagrams.jpg|thumb|upright=1.75|Simple examples of block-diagram composition]]
Line 69:
|}
Let’sUsing saythe thatsequential wecomposition wantoperator to connect<code>:</code> the output of <code>+</code> can be routed to the input of <code>abs in order</code> to compute the [[absolute value]] of the output signal. This connection can be done using the sequential composition operator ':' (colon):
<source lang=cpphaskell>
process = + : abs;
</source>
Here is an example of parallel composition (a stereo cable) using the operator '<code>,'</code> (comma)operator that puts in parallelarranges its left and right expressions: in parallel. This is analogous to a stereo cable.
<source lang=cpphaskell>
process = _,_;
</source>
These operators can be arbitrarily combined. ForThe examplefollowing tocode multiplymultiplies thean input signal bywith 0.5 one can write:
<source lang=cpphaskell>
process = _,0.5 : *;
</source>
The above may be rewritten in [[currying|curried]] form:
Taking advantage of some syntactic sugar the above example can be rewritten (using what functional programmers know as curryfication):
<source lang=cpphaskell>
process = *(0.5);
</source>
The recursive composition operator '<code>~'</code> can be used to create block-diagrams with cycles (that include an implicit one-sample delay). Here is thean example of an integrator that takes an input signal X and computes an output signal Y such that Y(t) = X(t) + Y(t−1):