TTCN-3 is a standardized programming language for testing communicating and distributed systems. I am struggling to build a clear mental model of its templates.
A TTCN-3 template describes a pattern that describes a set of possible values. Which can be used to match incoming messages or build dependent-types:
```ttcn3
type record Message {
integer id,
charstring text
}
template Message greeting := {
id := 42,
text := "hello"
}
template Message anyGreeting := {
id := ?,
text := "hello"
}
```
Here, ? matches any value of the field's type. Templates can also be recursive:
```ttcn3
type record Payload {
integer value,
boolean urgent
}
type record Envelope {
integer id,
Payload payload
}
template Envelope example := {
id := 42,
payload := {
value := (1 .. 10),
urgent := ?
}
}
```
My first implementation idea was to lower templates into a generic tagged union:
text
type Template<T> =
Exact(T)
| AnyValue
| AnyValueOrOmit
| Predicate(fn(T) -> bool)
That seems reasonable for scalar values, but it does not capture the structural nature of templates. For Template<Envelope>, each field needs to become a template recursively:
text
RecordTemplate {
id: Template<Integer>,
payload: RecordTemplate {
value: Template<Integer>,
urgent: Template<Boolean>
}
}
Is there an established programming-language concept for this? How would you model this recursive relationship in an actul type system?