diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-25 08:15:21 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-25 08:15:21 +0200 |
| commit | d3781941c182fdc2971bac09b33b273e46232b00 (patch) | |
| tree | 2e7f5f96c66d6675c03e7e79855369694a985aa5 | |
| parent | 24bc06c9d553a94306534c9d41cb632ebfd36aae (diff) | |
| download | lambda-nantes-d3781941c182fdc2971bac09b33b273e46232b00.tar.gz | |
Evaluate both side of application
| -rw-r--r-- | rust/src/lambda.rs | 9 | ||||
| -rw-r--r-- | rust/src/parser.rs | 13 |
2 files changed, 18 insertions, 4 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index 0080f63..b05bd22 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -17,7 +17,7 @@ pub fn run(arg: &str) -> String { fn interpret(arg: &Value) -> Value { match arg { - Value::App(l, r) => apply(&interpret(l), r), + Value::App(l, r) => apply(&interpret(l), &interpret(r)), other => other.clone(), } } @@ -87,4 +87,11 @@ mod lambda_test { let value = parse("(((lam x (lam x x)) 13) 12)"); assert_eq!(Value::Num(12), interpret(&value)); } + + #[test] + fn interpretation_applies_to_both_sides_of_application() { + let value = parse("((lam x x) ((lam x x) 12))"); + assert_eq!(Value::Num(12), interpret(&value)); + } + } diff --git a/rust/src/parser.rs b/rust/src/parser.rs index c85a425..9dc0bb8 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -250,12 +250,19 @@ mod tests { type Strategy = BoxedStrategy<Self>; fn arbitrary_with(_args: ()) -> Self::Strategy { - prop_oneof![ + let identifier = "\\pL(\\pL|\\pN)*"; + let leaf = prop_oneof![ any::<i32>().prop_map(Num), any::<bool>().prop_map(Bool), // see https://unicode.org/reports/tr18/#General_Category_Property for one letter unicode categories - "\\pL(\\pL|\\pN)*".prop_map(Sym), - ] + identifier.prop_map(Sym), + ]; + leaf.prop_recursive(4, 128, 5, move |inner| { + prop_oneof![ + (inner.clone(), inner.clone()).prop_map(|(l, r)| App(Box::new(l), Box::new(r))), + (identifier, inner).prop_map(|(var, body)| Lam(var, Box::new(body))), + ] + }) .boxed() } } |
