Skip to content

Type System Reference

Complete reference for USL's type system.

Primitive Types

String      // Text
Int         // 64-bit integer
Float       // 64-bit floating point
Boolean     // true or false
Timestamp   // Point in time
Date        // Calendar date
Time        // Time of day

Custom Types

type UserId = String
type Email = String
type Money = Decimal

Collections

List[T]           // Ordered collection
Set[T]            // Unique elements
Map[K, V]         // Key-value pairs

Option Type

Option[T]         // Some(value) or None

match optionalValue {
  Some(v) => useValue(v)
  None => defaultValue()
}

Result Type

Result[T, E]      // Ok(value) or Err(error)

match result {
  Ok(v) => process(v)
  Err(e) => handleError(e)
}

Enums

enum Status {
  Active
  Inactive
}

Variants (Sum Types)

variant PaymentMethod {
  CreditCard { number: String, cvv: String }
  PayPal { email: Email }
  BankTransfer { iban: String }
}

Type Inference

USL infers types in many contexts:

let x = 42              // Inferred: Int
let list = [1, 2, 3]    // Inferred: List[Int]

Type Constraints

function max<T: Comparable>(a: T, b: T) -> T {
  if a > b { a } else { b }
}

Type Aliases

type UserId = String
type UserMap = Map[UserId, User]

Back to Overview