From 06798d622327707ca3f3b42d65fc3d1a25ae3c57 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 10 Aug 2025 18:38:49 +0300 Subject: Added term level type literals (for function type signatures) --- src/sexp/step.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/sexp/step.rs') diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 11df257..c26dce9 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -1,5 +1,6 @@ use crate::sexp::{SExp, SExp::*, SLeaf::*, util::*}; +use crate::r#type::{Type::*, util::*}; impl SExp { @@ -521,6 +522,29 @@ impl SExp { } }, + // Type arrow + SCons(op, l) if *op == Atom(Arr) => { + let ls = l.parts(); + let t1 = ls.get(0).ok_or("wrong list length".to_string())?; + let t2 = ls.get(1).ok_or("wrong list length".to_string())?; + match (t1.clone().multistep()?, t2.clone().multistep()?) { + (Atom(Ty(a)), Atom(Ty(b))) => Ok(Atom(Ty(arr(a.clone(), b.clone())))), + _ => Err("invalid args".to_string()), + } + }, + + // Type list + SCons(op, l) if (*op).is_type_lit() => { + let mut res = vec![]; + for exp in std::iter::once(*op).chain(l.parts()) { + res.push(match exp.multistep()? { + Atom(Ty(t)) => Ok(t), + e => Err(format!("not a type: {e}")), + }?); + } + Ok(Atom(Ty(List(res)))) + }, + // Print SCons(op, l) if *op == Atom(Print) => { println!("{}", *l); -- cgit v1.2.3