Rustica Programming Language

Rustica is a novel programming language with language integrated query (LINQ) technology and a robust effect system, providing developers with a seamless, type-safe, and expressive interface for database interaction directly within the language's syntax and type system.

Data-Centric

  • Reads and writes data using only native language syntax like comprehensions and iterators, no SQL or ORM needed
  • Fully compatible with PostgreSQL native data types, zero copy or conversion, seamless flow from API to database
  • Provides comprehensive migration toolchain, you maintain your schema and Rustica handles the rest

Safe & Efficient

  • Strong static type system catches most errors at compile time, ensuring code correctness and reducing mental burden
  • Functional-style immutable data structures, avoiding side effects and unsafe state changes, improving concurrency
  • Generates efficient WebAssembly bytecode with AoT compilation, C/C++ level performance in a secure sandbox environment

DX First

  • Declarative and natural syntax, effortlessly write readable and maintainable code, making complex logic easy to express and understand
  • Orthogonal, expressive, and intuitive design: fewer core concepts and syntax rules, yet greater composability.
  • Supports structured/graphical programming with a gentle learning curve for all developers

Type System

  • Prefix polymorphism: achieves high-level abstraction and safe reuse of functions, effects, and data structures
  • Side effects are precisely annotated in types, assisting both compiler optimizations and risk assessment for callers
  • Cardinality and multiset types provide intuitive and type-safe annotations for LINQ syntax, enhancing clarity and safety

Effect System

  • Side effects (I/O, state, exceptions, etc.) are no longer scattered in code but abstracted as composable effects, keeping core logic pure
  • Exceptions, coroutines, async operations, and transaction control are all unified under a single abstraction, less to worry about
  • Effect handlers are easily replaced without changing business logic, making it easier to migrate to new environments

Graph-Relational Model

  • "Tables and foreign keys" are now "concepts and links" (DDL SQL by compiler), making schema design more programming-friendly
  • Database values are unified as "multisets" for consistent behavior, addressing SQL limitations such as NULL semantics.
  • Cardinality introduces predictable and computable quantity constraints to the multiset type system (optionality + multiplicity).

Examples

Data Modeling: Schema Definition

concept User {
  name: Text
  following: User [0, inf]
  exclusive (name)
}

concept Project {
  name: Text
  owner: User [1, 1]
  exclusive (owner, name)
}
TBD

Data API: retrieve data for user page

// API definition, type is also the document
api GET "/${username}"
  -> { View, HTTP }  // API sugar handles these effects
     Bag {
       name: Text,
       following_count: Int,
       projects: Bag {
         name: Text,
       } [0, inf]
     }
     [1, 1]
{
  // API implementation is a single query
  view_table ()  // Bag User [0, inf], View effect

  // Find the user matching the URL parameter
  |> filter (\user case user of
       | { name, .. } => name == username
     )  // Bag User [0, 1] due to exclusiveness

  // Retrieve all interested data in one go
  |> map (\User::{ id, name, following, .. } -> {
       name,
       following_count: following.count (),

       // Subquery: find all projects of the user
       projects: view_table ()  // Bag Project [0, inf]
         |> filter_map (\project case project of
              | { name, owner, .. } if owner is user
                => Some({ name })
              | _ => None
            )  // Bag { name: Text } [0, inf]
     })  // Bag { .. } [0, 1]

  // Returns 404 if the user is not found
  |> unwrap_or_404 ()  // Bag { .. } [1, 1], HTTP effect
}
TBD

Formal Definition

Drafter: CAIMEO | 2025-08-29

Glossary

TBD

Reference