feat: implement type classes / traits
Add support for type classes (traits) with full parsing, type checking, and
validation. The implementation includes:
- Trait declarations: trait Show { fn show(x: T): String }
- Trait implementations: impl Show for Int { fn show(x: Int) = ... }
- Super traits: trait Ord: Eq { ... }
- Trait constraints in where clauses: where T: Show + Eq
- Type parameters on traits: trait Functor<F> { ... }
- Default method implementations
- Validation of required method implementations
This provides a foundation for ad-hoc polymorphism and enables
more expressive type-safe abstractions.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,8 +49,9 @@ impl Module {
|
||||
Declaration::Function(f) => f.visibility == Visibility::Public,
|
||||
Declaration::Let(l) => l.visibility == Visibility::Public,
|
||||
Declaration::Type(t) => t.visibility == Visibility::Public,
|
||||
// Effects and handlers are always public for now
|
||||
Declaration::Effect(_) | Declaration::Handler(_) => true,
|
||||
Declaration::Trait(t) => t.visibility == Visibility::Public,
|
||||
// Effects, handlers, and impls are always public for now
|
||||
Declaration::Effect(_) | Declaration::Handler(_) | Declaration::Impl(_) => true,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
||||
Reference in New Issue
Block a user