| Crates.io | csw-derive |
| lib.rs | csw-derive |
| version | 0.1.0 |
| created_at | 2025-12-05 16:54:04.732327+00 |
| updated_at | 2025-12-05 16:54:04.732327+00 |
| description | Type system derivation engine for the Categorical Semantics Workbench - derive type theories from categorical structures |
| homepage | https://github.com/ibrahimcesar/categorical-semantics-workbench |
| repository | https://github.com/ibrahimcesar/categorical-semantics-workbench |
| max_upload_size | |
| id | 1968699 |
| size | 33,821 |
Type system derivation engine for the Categorical Semantics Workbench.
This crate implements the Curry-Howard-Lambek correspondence as an automated construction: given a categorical structure specification, it derives the corresponding type system with typing rules, reduction rules, and structural properties.
The derivation process transforms categorical structures into type systems:
| Categorical Structure | Derived Type System |
|---|---|
| Terminal object | Unit type (1) |
| Products (A × B) | Pair types with fst/snd |
| Coproducts (A + B) | Sum types with case |
| Exponentials (B^A) | Function types (A → B) |
| Tensor (A ⊗ B) | Linear pairs |
| Linear hom (A ⊸ B) | Linear functions |
use csw_core::CategoryBuilder;
use csw_derive::Deriver;
// Define a Cartesian Closed Category
let ccc = CategoryBuilder::new("STLC")
.with_base("Int")
.with_base("Bool")
.with_terminal()
.with_products()
.with_exponentials()
.cartesian()
.build()
.unwrap();
// Derive the type system
let type_system = Deriver::derive(&ccc);
// Print the derived type system
println!("{}", type_system);
A TypeSystem contains:
For a CCC specification, the derivation produces:
Types:
τ ::= Int | Bool | 1 | τ × τ | τ → τ
Terms:
e ::= x | () | (e, e) | fst e | snd e | λx.e | e e
Typing Rules:
Γ ⊢ () : 1 (unit-intro)
Γ ⊢ a : A Γ ⊢ b : B
──────────────────────── (pair-intro)
Γ ⊢ (a, b) : A × B
...
Structural Rules:
Weakening: ✓
Contraction: ✓
Exchange: ✓
Licensed under either of Apache License, Version 2.0 or MIT license at your option.