  The pivotal role that event correlation technology plays in todays
applications has lead to the emergence of different families of event
correlation approaches with a multitude of specialized correlation semantics,
including computation models that support the composition and extension of
different semantics. However, type-safe embeddings of extensible and composable
event patterns into statically-typed general-purpose programming languages have
not been systematically explored so far. Event correlation technology has often
adopted well-known and intuitive notations from database queries, for which
approaches to type-safe embedding do exist. However, we argue in the paper that
these approaches, which are essentially descendants of the work on monadic
comprehensions, are not well-suited for event correlations and, thus, cannot
without further ado be reused/re-purposed for embedding event patterns. To
close this gap we propose PolyJoin, a novel approach to type-safe embedding for
fully polyvariadic event patterns with polymorphic correlation semantics. Our
approach is based on a tagless final encoding with uncurried higher-order
abstract syntax (HOAS) representation of event patterns with n variables, for
arbitrary $n \in \mathbb{N}$. Thus, our embedding is defined in terms of the
host language without code generation and exploits the host language type
system to model and type check the type system of the pattern language. Hence,
by construction it impossible to define ill-typed patterns. We show that it is
possible to have a purely library-level embedding of event patterns, in the
familiar join query notation, which is not restricted to monads. PolyJoin is
practical, type-safe and extensible. An implementation of it in pure multicore
OCaml is readily usable.
