Stream pattern components are matched against the corresponding elements of a stream. Finally, the component ident simply binds the identifier to the stream being matched. If the following components do not match, the exception Stream. Error is raised. If none of the first components of the stream patterns match, the exception Stream.
Failure is raised.
The streams hold the count of their elements discarded. The optional pattern before the first stream pattern is bound to the stream count before the matching. This expression is evaluated only in case of error. See Functional programming using Caml Light for a more gentle introductions to streams, and for some examples of their use in writing parsers. A more formal presentation of streams, and a discussion of alternate semantics, can be found in Parsers in ML by Michel Mauny and Daniel de Rauglaudre, in the proceedings of the 1992 ACM conference on Lisp and Functional Programming.