Skib

Introduction

Skib is a systems functional programming language. The core ideology of Skib is predictability, simple rules, and the absence of implicit behavior (acting as an anti-C++ approach). The language provides high-level abstractions (Algebraic Data Types, Pattern Matching, Typeclasses) while maintaining total manual control over memory and hardware resources (inspired by Zig).

Skib and SkibCore

The compilation pipeline is conceptually divided into two tiers:

  1. Skib: The full-featured language containing implicits, procedural macros, and syntactic sugar.
  2. SkibCore: A minimalist intermediate representation (IR). All complex Skib features are desugared into SkibCore, which operates strictly on ADTs, structs, functions, and explicit memory allocations. SkibCore is then compiled into ANSI C98 or LLVM IR.

Core Principles

Type System

The Skib type system is primarily structural and nominal, heavily featuring Algebraic Data Types (ADTs) and structs, with ad-hoc polymorphism achieved through typeclasses.

Core Constructs

Type Inference

Skib implements local type inference.

Typeclasses (Traits)

Typeclasses are used for ad-hoc polymorphism. They allow defining shared behavior for types (e.g., custom allocators, resource release via deinit, or smart pointer logic inside the standard library).

Functions and Syntax

Application and Currying

Function application uses explicit parentheses: f(a, b, c).

Pipeline Operator

To prevent deep nesting of parentheses ((())) when calling multiple functions, Skib provides a pipeline operator |>.

skolemization(x)
  |> skibidization(4)
  |> kekszation(5)

Tail Call Optimization (TCO)

Tail recursion must be optimized into a loop to prevent stack overflows and save stack frame allocations. A specific keyword or annotation (e.g., tailcall) will be required so the compiler can throw an error if the optimization is mathematically impossible in a given context.

Memory Management

Skib utilizes a purely manual memory management model. There is no affine type system, no move semantics by default, and no borrow checker.

Allocators and defer

Memory is controlled using Zig-style allocators. Standard malloc is considered too slow and error-prone; instead, users pass explicit Allocator or Arena instances. To clean up resources at the end of a scope, Skib uses the defer keyword.

let arena = Arena.init();
defer arena.deinit();

Smart Pointers

The standard library will provide explicit smart pointers (e.g., similar to Box or Unique). Since there is no borrow checker, ownership logic is maintained by explicit traits (typeclasses) handling deinit when the pointer is explicitly dropped or goes out of scope.

Implicit Parameters (Contexts)

To avoid threading an Allocator through every single function call manually, Skib allows strictly scoped implicit parameters.

// Overriding the implicit allocator explicitly at the call site
skolemization(x, ex alloc = &myAlloc)

Metaprogramming

Skib requires a powerful metaprogramming system primarily to handle automatic code generation for ADTs and Structs (e.g., deriving Serialize, Eq, Show).

Procedural Macros

Macros operate as Tokens -> Tokens transformations (similar to Rust). They are executed lexically before type inference.

@derive(Serialize)
struct S {
  @serde(skip)
  hidden: Int
}

…