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:
14
src/types.rs
14
src/types.rs
@@ -788,6 +788,20 @@ impl TypeEnv {
|
||||
},
|
||||
);
|
||||
|
||||
// Add Reader effect
|
||||
env.effects.insert(
|
||||
"Reader".to_string(),
|
||||
EffectDef {
|
||||
name: "Reader".to_string(),
|
||||
type_params: vec!["R".to_string()],
|
||||
operations: vec![EffectOpDef {
|
||||
name: "ask".to_string(),
|
||||
params: Vec::new(),
|
||||
return_type: Type::Var(0), // R
|
||||
}],
|
||||
},
|
||||
);
|
||||
|
||||
// Add Some and Ok, Err constructors
|
||||
// Some : fn(a) -> Option<a>
|
||||
let a = Type::var();
|
||||
|
||||
Reference in New Issue
Block a user