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:
- Skib: The full-featured language containing implicits, procedural macros, and syntactic sugar.
- 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
- No Garbage Collector (GC): All memory is managed manually.
- No Borrow Checker: The compiler does not track reference lifetimes (unlike Rust). Avoiding memory leaks and dangling pointers is solely the programmer’s responsibility.
- Explicit over Implicit: The language rejects features like implicit function currying and silent C++-style constructor overloads, which obscure performance costs and trigger hidden heap allocations.
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
- Structs: Standard product types used for data grouping.
- Algebraic Data Types (ADTs): Sum types with full Pattern Matching support.
Type Inference
Skib implements local type inference.
- Global type inference (e.g., global Hindley-Milner) is strictly rejected because it leads to confusing error messages in unrelated parts of the codebase.
- Function signatures (including generics) must be explicitly annotated.
- Inside a function body, the types of variable bindings (
let) are inferred top-down.
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).
- No Space Application: Haskell-style space application (
f a b c) is rejected. - No Auto-Currying: Automatic currying creates implicit closures and causes severe performance drops due to hidden heap allocations.
- Custom Operators: The language supports custom user-defined operators (which act as standard functions).
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.
- Implicits are resolved via the calling function’s signature.
- Searching the global scope or class scope for implicits (Scala-style) is forbidden.
- Implicits are declared at the end of a function call using a specific keyword (e.g.,
ex), preventing ambiguity with regular arguments.
// 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
}…