Standard Typeclasses Approach
Relevant source files
The following files were used as context for generating this wiki page:
The Standard Typeclasses Approach in Jazz is a core architectural design philosophy intended to bridge the gap between powerful functional programming paradigms and developer accessibility. Unlike Haskell, which utilizes a type system heavily oriented toward category theory (e.g., Monads, Semigroupoids), Jazz adopts a more "standard" nomenclature and structural approach to typeclasses. This system is designed to provide the benefits of strong, static typing and type inference without the steep learning curve associated with traditional functional category theory.
The approach is currently integrated into the active development path within the jazz-next/ directory, which serves as the canonical implementation target for the compiler's analyzer, type inference engine, and runtime behavior.
Sources: README.md:12-14, jazz-next/README.md:1-5, AGENTS.md:11-13
Design Philosophy and Motivation
The primary motivation for the Standard Typeclasses Approach is to reduce beginner confusion. In Jazz, typeclasses are named according to their functional purpose rather than their mathematical origin. For example, instead of encountering "Monoids" or "Functors," developers interact with classes like Collection and Orderable.
Core Objectives
- Accessibility: Replace category theory terminology with intuitive, descriptive names.
- Strong Static Typing: Maintain a robust type system that catches errors at compile-time.
- Type Inference: Implement a "core expression subset" that allows the compiler to deduce types without explicit annotations, though explicit signatures are supported.
Sources: README.md:12-18, README.md:90-95
Architectural Integration
The implementation of this approach is distributed across several key components in the jazz-next compiler suite. The logic flows from initial surface parsing through a lowering phase into a semantic analyzer that enforces typeclass-related constraints.
The diagram above illustrates the data flow from raw source code to an inferred, type-checked result within the jazz-next compiler.
Sources: jazz-next/README.md:12-23
Component Responsibilities
| Component | Responsibility in Typeclass Approach |
|---|---|
Parser.hs | Handles surface syntax for type signatures (e.g., :: Int -> Int). |
Lower.hs | Converts surface AST into an analyzer-facing core AST. |
Analyzer.hs | Performs binding/signature coherence checks and scope-aware analysis. |
TypeInference.hs | Plumbs inference results and carries semantic errors/warnings. |
Driver.hs | Gates compilation based on warning-as-error settings and semantic errors. |
Sources: jazz-next/README.md:12-23
Language Features and Syntax
The Standard Typeclasses Approach is supported by several verified implementation features that dictate how types and functions behave within the system.
Functional Behavior
- Currying and Partial Application: Functions are curried by default. This allows functions to be partially applied to create new functions, such as
add10 = (+10). - Purity Enforcement: Functions are pure by default. Impure functions must be explicitly denoted with a
!suffix (e.g.,print!,greet!). The compiler performs stub purity enforcement, preventing impure functions from being called within pure binding bodies.
Conceptual relationship of the "Standard" typeclasses replacing category theory structures.
Sources: README.md:19-25, README.md:44-55, README.md:79-85
Syntax Examples
Type Signatures and Inference
While types are inferred, explicit signatures use the :: operator.
// Explicit signature for an Integer to Boolean function
isEven :: Integer -> Bool.
isEven = \(i) -> mod(i, 2) == 0.
Sources: README.md:93-95
Operator Application
The $ operator is utilized as a right-associative, zero-precedence function application operator to avoid excessive parentheses, often used when passing the result of one type-checked expression to another.
// Equivalent to print!(add10List(nums))
print! $ add10List nums.
Sources: README.md:58-62
Implementation Status
The project tracks the progress of the type system and typeclasses through a formal status matrix.
| Feature | Status | Implementation Path |
|---|---|---|
| Strong, static typing | Verified | jazz-next/ |
| Type inference | Verified | jazz-next/ |
| Curried functions | Verified | jazz-next/ |
Purity enforcement (!) | Verified (Stub) | jazz-next/ |
| ADTs / Pattern Matching | Planned | N/A |
Sources: README.md:16-25, scripts/check-docs.sh:25-30
Conclusion
The Standard Typeclasses Approach represents Jazz's commitment to "functional power without the jargon." By anchoring the type system in the jazz-next/ implementation and utilizing descriptive naming conventions like Collection and Orderable, the project provides a sophisticated static type system that remains accessible to developers familiar with imperative or less mathematically-rigorous functional languages.
Sources: README.md:12-14, jazz-next/README.md:1-5