am-kantox/cure-lang
{ "createdAt": "2025-10-04T11:50:04Z", "defaultBranch": "main", "description": "Cure language compiling to BEAM with FSM primitives and Dependent types", "fullName": "am-kantox/cure-lang", "homepage": null, "language": "HTML", "name": "cure-lang", "pushedAt": "2026-01-06T05:50:52Z", "stargazersCount": 87, "topics": [], "updatedAt": "2026-01-06T05:50:57Z", "url": "https://github.com/am-kantox/cure-lang"}Cure Programming Language
Section titled “Cure Programming Language”Cure is a dependently-typed programming language for the BEAM virtual machine. It provides compile-time verification through dependent types, native finite state machine constructs, and integration with SMT solvers for automated theorem proving.
Version: 0.7.0
Last Updated: November 2025
Overview
Section titled “Overview”Cure compiles to BEAM bytecode and runs on the Erlang virtual machine. The language emphasizes static verification while maintaining interoperability with the Erlang and Elixir ecosystems.
Key Characteristics
Section titled “Key Characteristics”- Dependent type system with refinement constraints
- First-class finite state machines with transition verification
- SMT solver integration (Z3, CVC5) for constraint solving
- Pattern matching with exhaustive case analysis
- Type-directed optimizations during compilation
- Standard library with common data structures and operations
- Language Server Protocol implementation for editor integration
Building
Section titled “Building”Prerequisites:
- Erlang/OTP 20 or later
- Make
- Unix-like environment
make allThe compiler executable will be available as ./cure.
Compile a Cure source file:
./cure <input-file>.cureRun the compiled module:
erl -pa _build/ebin -noshell -eval "'ModuleName':main(), init:stop()."Common options:
-o, --output <file>- Specify output file-d, --output-dir <dir>- Set output directory--verbose- Enable detailed compilation output--no-type-check- Skip type checking phase
Language Features
Section titled “Language Features”Module System
Section titled “Module System”Modules define namespaces and export interfaces:
module Example do export [function/1, other_function/2]
import Std.List [map, filter]
def function(x: Int): Int = x * 2endDependent Types
Section titled “Dependent Types”Types can express constraints verified at compile time:
# Vector with length tracked in the typedef safe_head(v: Vector(T, n)): T when n > 0 = head(v)
# Refinement types for constrained valuesdef safe_divide(a: Int, b: {x: Int | x != 0}): Int = a / bFinite State Machines
Section titled “Finite State Machines”FSMs are first-class language constructs:
fsm TrafficLight do Red --> |timer| Green Green --> |timer| Yellow Yellow --> |timer| Red Green --> |emergency| RedendThe compiler verifies reachability, detects unreachable states, and generates BEAM behavior implementations.
Pattern Matching
Section titled “Pattern Matching”Match expressions provide exhaustive case analysis:
def classify(x: Int): Atom = match x do n when n < 0 -> :negative 0 -> :zero n when n > 0 -> :positive endThe compiler ensures all cases are handled.
Records
Section titled “Records”Record types with field access and immutable updates:
record Person do name: String age: Intend
def update_age(person: Person, new_age: Int): Person = Person{person | age: new_age}Standard Library
Section titled “Standard Library”The standard library provides common functionality:
Std.Core- Basic types and operationsStd.List- List processing (map, filter, fold)Std.Result- Error handling with Result typeStd.Io- Input/output operationsStd.Fsm- FSM runtime operationsStd.String- String manipulationStd.Math- Mathematical operationsStd.Pair- Tuple operationsStd.Vector- Length-indexed vectorsStd.Show- Value serializationStd.System- System-level operationsStd.Rec- Record utilities
See docs/STD_SUMMARY.md for complete API documentation.
Type System
Section titled “Type System”Refinement Types
Section titled “Refinement Types”Refinement types add logical constraints to base types:
type NonZero = {x: Int | x != 0}type Percentage = {p: Int | 0 <= p and p <= 100}Constraints are checked at compile time using SMT solvers.
Type Inference
Section titled “Type Inference”The compiler infers types for local bindings:
def example(): Int = let x = 42 # x: Int inferred let y = [1, 2, 3] # y: List(Int) inferred x + length(y)Compilation Pipeline
Section titled “Compilation Pipeline”- Lexical analysis: Source code to token stream
- Parsing: Token stream to abstract syntax tree
- Type checking: Dependent type verification with SMT solving
- Optimization: Monomorphization, specialization, inlining
- Code generation: AST to BEAM bytecode
Type-directed optimizations provide 25-60% performance improvement over baseline compilation.
Project Structure
Section titled “Project Structure”cure/├── src/│ ├── lexer/ # Tokenization│ ├── parser/ # Syntax analysis and AST generation│ ├── types/ # Type system and type checking│ ├── codegen/ # BEAM bytecode generation│ ├── fsm/ # FSM compilation and runtime│ ├── smt/ # SMT solver integration│ ├── lsp/ # Language server implementation│ └── runtime/ # Runtime system integration├── lib/std/ # Standard library modules├── test/ # Test suites├── examples/ # Example programs└── docs/ # DocumentationTesting
Section titled “Testing”Run the test suite:
make testTests cover lexical analysis, parsing, type checking, FSM compilation, and code generation.
Examples
Section titled “Examples”The examples/ directory contains working programs:
01_list_basics.cure- List operations02_result_handling.cure- Error handling with Result type03_option_type.cure- Optional values04_pattern_guards.cure- Pattern matching with guards05_recursion.cure- Recursive functions06_fsm_traffic_light.cure- FSM implementation07_refinement_types_demo.cure- Refinement type constraints08_typeclasses.cure- Typeclass system usage
Documentation
Section titled “Documentation”Core documentation:
docs/LANGUAGE_SPEC.md- Language specificationdocs/TYPE_SYSTEM.md- Type system detailsdocs/FSM_USAGE.md- FSM programming guidedocs/STD_SUMMARY.md- Standard library referencedocs/FEATURE_REFERENCE.md- Quick reference
Advanced topics:
docs/DEPENDENT_TYPES_GUIDE.md- Dependent types and SMT verificationdocs/TYPECLASS_RESOLUTION.md- Typeclass implementationdocs/SMT_SOLVER_ADVANCED.md- SMT solver integration details
Development Status
Section titled “Development Status”Implemented
Section titled “Implemented”- Complete lexer with position tracking
- Recursive descent parser with error recovery
- Dependent type checker with refinement types
- FSM compilation to BEAM behaviors
- BEAM bytecode generation with OTP compatibility
- Standard library with 15 modules
- Type-directed optimizations
- Language Server Protocol implementation
- SMT solver integration (API level)
- Record operations with field access
- Pattern matching with guards
Planned
Section titled “Planned”- Pipe operator (
|>) implementation - Typeclass/trait system expansion
- If-then-else expressions
- String interpolation
- Enhanced error messages with suggestions
- Package management system
See docs/TODO.md for detailed roadmap.
Performance
Section titled “Performance”Compilation times:
- Small files (<100 lines): <1 second
- Medium projects (1K-10K lines): 5-30 seconds
- Large projects (100K+ lines): 30-300 seconds
Runtime characteristics:
- Function call overhead: ~10ns (after optimization)
- FSM event processing: ~1μs
- Type checking: Zero runtime overhead (compile-time only)
- Memory usage: Comparable to equivalent Erlang code
Contributing
Section titled “Contributing”Contributions are welcome. Priority areas include:
- Standard library expansion
- Optimization improvements
- Documentation and examples
- IDE tooling enhancements
- Test coverage expansion
License
Section titled “License”To be determined.