summaryrefslogtreecommitdiff
path: root/lambda-calcul/rust/src/ast.rs
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-10-09 15:21:49 +0200
committerArnaud Bailly <arnaud@pankzsoft.com>2025-10-09 15:21:49 +0200
commit5719458b477e05a60b323ba3bb910432b36d30d7 (patch)
tree80112a5d94dbf52d1e9fa759e88cdd417f6d0c8e /lambda-calcul/rust/src/ast.rs
parentbf7f549e309a4da97def326b3fdf19a4d8833450 (diff)
downloadlambda-nantes-5719458b477e05a60b323ba3bb910432b36d30d7.tar.gz
feat: introduce typing of expressions
Diffstat (limited to 'lambda-calcul/rust/src/ast.rs')
-rw-r--r--lambda-calcul/rust/src/ast.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/lambda-calcul/rust/src/ast.rs b/lambda-calcul/rust/src/ast.rs
index 0aaeab4..db3b4a7 100644
--- a/lambda-calcul/rust/src/ast.rs
+++ b/lambda-calcul/rust/src/ast.rs
@@ -6,6 +6,22 @@ use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
+pub enum Type {
+ Int
+}
+
+impl Display for Type {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "Type")
+ }
+}
+
+#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
+pub enum TypeError {
+ UnknownType(Value),
+}
+
+#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum Value {
Num(i32),
Bool(bool),
@@ -14,6 +30,13 @@ pub enum Value {
Lam(String, Box<Value>),
Def(String, Box<Value>),
Let(String, Box<Value>, Box<Value>),
+ // typed abstraction
+ TLam(String, Type, Box<Value>),
+ // reified type
+ // this is unsound as we are not in a dependently typed language
+ // but useful to unify external representation (AST). In theory,
+ // we should separate AST from Terms
+ Type(Type)
}
use Value::*;
@@ -50,6 +73,8 @@ impl Display for Value {
Value::Lam(var, body) => write!(f, "(lam {} {})", var, body),
Value::Def(var, value) => write!(f, "(def {} {})", var, value),
Value::Let(var, value, body) => write!(f, "(let ({} {}) {})", var, value, body),
+ Value::TLam(var,typ, body) => write!(f, "(lam ({} {}) {})", var, typ, body),
+ Value::Type(typ) => write!(f, ":{}", typ),
}
}
}