Domain modelling with DCL types

This guide uses DCL Language 1.1. The expanded type system described here is not available to files declaring DCL Language 1.0.

DCL types encode domain distinctions, not merely storage representation. Built-in types provide the foundations; record shapes, enum shapes, collections, constraints, and measures let a model give those values business meaning.

Choose the type that carries the meaning

  • Use Integer for whole numbers and Number when fractions are meaningful.
  • Use a record shape for a named group of fields that belongs together.
  • Use an enum shape for a closed choice between alternatives.
  • Use List<T> when a value contains a collection of another type.
  • Use a measure when numerically similar values have different domain meanings.
  • Use min, max, and default for numeric structural constraints.

Compose a domain model

The example below combines nested address and order shapes, closed payment and delivery alternatives, typed enum values, collections, measured numeric fields, and range constraints. It is compiled as part of the website's example validation.

domain-types.dcl
language dcl 1.1

measure Items
measure Weight
measure Days

shape Product {
  stock: Integer
  price: Number
}

shape RetryConfiguration {
  attempts: Integer min 0 max 10 default 3
  delaySeconds: Number min 0 max 60 default 1.5
}

shape Address {
  line1: Text required
  city: Text required
  postcode: Text required
}

shape Customer {
  name: Text required
  address: Address required
}

shape Currency enum {
  GBP
  USD
  EUR
}

shape HexColour {
  value: Text required
}

shape Colour enum {
  Red
  Green
  Blue
  Hex is HexColour
}

shape CardDetails {
  token: Text required
}

shape BankAccount {
  accountNumber: Text required
}

shape PaymentMethod enum {
  Cash
  Card is CardDetails
  BankTransfer is BankAccount
}

shape SearchValue enum {
  TextValue is Text
  NumericValue is Integer
}

shape Failure {
  name: Text
  reason: Text required
  code: Number
}

shape Result enum {
  Success
  Failed is List<Failure>
}

shape DeliveryMethod enum {
  Collection
  HomeDelivery is Address
}

shape OrderLine {
  productId: Text required
  quantity: Integer<Items> min 1 required
  unitWeight: Number<Weight> min 0 required
}

shape Order {
  lines: List<OrderLine> required
  payment: PaymentMethod required
  delivery: DeliveryMethod required
}

shape RetentionPolicy {
  retention: Integer<Days> min 1 required
}

Open in Playground

Keep data and behaviour distinct

An enum shape such as Result is a reusable domain data type. A capability outcome is behavioural: it records what result the capability can cause. DCL may use the same supporting types in both places without making enum alternatives and outcomes interchangeable.

See the type-system reference for the exact syntax and compiler validation rules.