feat: implement built-in State, Reader, and Fail effects
Add runtime support for the State, Reader, and Fail effects that were already defined in the type system. These effects can now be used in effectful code blocks. Changes: - Add builtin_state and builtin_reader fields to Interpreter - Implement State.get and State.put in handle_builtin_effect - Implement Reader.ask in handle_builtin_effect - Add Reader effect definition to types.rs - Add Reader to built-in effects list in typechecker - Add set_state/get_state/set_reader/get_reader methods - Add 6 new tests for built-in effects - Add examples/builtin_effects.lux demonstrating usage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -935,7 +935,7 @@ impl TypeChecker {
|
||||
}
|
||||
|
||||
// Built-in effects are always available
|
||||
let builtin_effects = ["Console", "Fail", "State"];
|
||||
let builtin_effects = ["Console", "Fail", "State", "Reader"];
|
||||
let is_builtin = builtin_effects.contains(&effect.name.as_str());
|
||||
|
||||
// Track this effect for inference
|
||||
@@ -1440,7 +1440,7 @@ impl TypeChecker {
|
||||
|
||||
// Built-in effects are always available in run blocks (they have runtime implementations)
|
||||
let builtin_effects: EffectSet =
|
||||
EffectSet::from_iter(["Console", "Fail", "State"].iter().map(|s| s.to_string()));
|
||||
EffectSet::from_iter(["Console", "Fail", "State", "Reader"].iter().map(|s| s.to_string()));
|
||||
|
||||
// Extend current effects with handled ones and built-in effects
|
||||
let combined = self.current_effects.union(&handled_effects).union(&builtin_effects);
|
||||
|
||||
Reference in New Issue
Block a user