···107107108108## Array Constraints
109109110110-Arrays can be constrained by length:
110110+A constraint block written after `T[]` applies to **the array itself** — typically bounding the number of items:
111111112112```mlf
113113tags: string[] constrained {
114114 minLength: 1,
115115- maxLength: 10,
115115+ maxLength: 10, // at most 10 tags
116116}
117117118118images: Uri[] constrained {
119119- maxLength: 4,
119119+ maxLength: 4, // at most 4 image URLs
120120+}
121121+```
122122+123123+### Constraining Array Items
124124+125125+To constrain **each item** rather than the array, wrap the item type in parentheses and put the constraint block inside:
126126+127127+```mlf
128128+record post {
129129+ /// Each tag: at most 100 characters
130130+ tags: (string constrained { maxLength: 100 })[],
131131+}
132132+```
133133+134134+Without the parentheses, the constraint binds to the array, not the items. The two forms can also be combined when you need both levels:
135135+136136+```mlf
137137+record post {
138138+ /// At most 20 tags; each tag at most 50 chars
139139+ tags: (string constrained { maxLength: 50 })[] constrained {
140140+ maxLength: 20,
141141+ },
142142+}
143143+```
144144+145145+For patterns you'll reuse, naming the constrained item type keeps the field declarations short — see [Custom Types](/docs/language-guide/custom-types/#array-items):
146146+147147+```mlf
148148+inline type Tag = string constrained { maxLength: 100 };
149149+150150+record post {
151151+ tags: Tag[],
120152}
121153```
122154
···7171}
7272```
73737474+### Array Items
7575+7676+Inline types are the cleanest way to constrain the items of an array. Writing the constraint directly on `T[]` binds it to the array (see [Array Constraints](/docs/language-guide/constraints/#array-constraints)); defining an inline type for the item lets the field declaration stay short while each element is still validated:
7777+7878+```mlf
7979+inline type Tag = string constrained { maxLength: 100 };
8080+inline type PositiveInt = integer constrained { minimum: 0 };
8181+8282+record post {
8383+ tags!: Tag[], // each tag constrained to 100 chars
8484+ viewCounts!: PositiveInt[], // each integer must be ≥ 0
8585+}
8686+```
8787+8888+This is equivalent to the parenthesized inline form `(string constrained { maxLength: 100 })[]` — pick whichever reads better at the call site. The inline-type form wins when the same shape appears in multiple fields.
8989+7490## Def Types
75917692When you want a type to be **shared and referenced by name** in the generated lexicon, use `def type`: