Coco Type Theory

We want to be extra-clear on the nature of our types, how we view them, and how we use them. This is foundational to achieving memory safety and performance without headaches.

Coco's type system combines:

  • Memory safety through ownership tracking (like Rust)
  • Maximum simplicity: No let, no mut, just & for all references
  • Smart compiler: Detects mutation, chooses passing strategy, optimizes automatically
  • Modern features: Primitive string type with ARC, first-class OOP, and auto-propagating errors
  • Zero-cost abstractions for high-level code that compiles to efficient machine code

Pages in this chapter:

  • Philosophy — The foundational principles: simple, transparent, safe. Covers our design decisions including no `let` keyword, mutable-by-default, just `&` for references (compiler detects mutation), smart parameter passing, ARC for strings, and OOP as a first-class citizen.
  • Primitive and Compound Types — Core types and how they compose. Includes integers, floats, booleans, the primitive `string` type with ARC and copy-on-write semantics, arrays, slices, tuples, structs, enums, and pointers.
  • References and Ownership — Memory safety through ownership tracking. Covers ownership fundamentals, smart parameter passing (automatic by-value vs by-reference), simple `&` references where the compiler detects mutation and enforces exclusive access automatically, string ownership with ARC, and the borrow checker.
  • Type Inference and Abstractions — How types are inferred and optimized. Includes inference rules, zero-cost abstractions through generics and monomorphization, iterators, inlining, and the trait system.
  • Language Comparisons — Where we stand relative to C, Rust, Go, C++, PHP, and Swift. Shows what we borrow from each language and where we differ.
  • Object-Oriented Programming — OOP as a first-class citizen. Covers classes vs structs, methods and `$this`, constructors, single inheritance, visibility modifiers (public/private/protected), polymorphism, traits vs inheritance, and best practices.
  • Error Handling — Practical error handling that merges Go and Zig's best ideas. Covers the `!T` error union syntax, automatic error propagation, explicit handling with `catch`, Go-style multiple returns, error wrapping, and best practices. Errors are values that propagate by default—handle them where it makes sense.
  • Generics — Parametric polymorphism and zero-cost abstractions in Coco's type system
  • The Mixed Type — Dynamic typing escape hatch for when you need to accept any value
Copyright (c) 2025 Ocean Softworks, Sharkk