From 23b2028bdce46d02209fc2df70fc5468a8beffa8 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 6 Aug 2025 14:15:12 +0300 Subject: Added boilerplate and tests for let-binds --- src/type/check.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/type/check.rs') diff --git a/src/type/check.rs b/src/type/check.rs index df3f4d9..d0ce807 100644 --- a/src/type/check.rs +++ b/src/type/check.rs @@ -81,6 +81,43 @@ impl SExp { /// assert_eq!(Atom(Not).type_check(), Ok(arr(List(vec![Boolean]), Boolean))); /// ``` /// + /// + /// **Let-binding types** + /// + /// Let-bindings are quite interesting. Implementation is still a bit uncertain, + /// but at least we know that + /// ```rust + /// use myslip::{ + /// r#type::{*, Type::*, TypeError::*, util::*}, + /// sexp::{SExp::*, SLeaf::*, util::*}, + /// }; + /// + /// assert_eq!( + /// scons( + /// scons(Let, scons(var("x"), scons(False, Nil))), + /// scons(var("x"), Nil) + /// ).type_check(), + /// Ok(Boolean) + /// ); + /// ``` + /// + /// As such it must be that the type of the let-binding s-expression is st. + /// ```rust + /// use myslip::{ + /// r#type::{*, Type::*, TypeError::*, util::*}, + /// sexp::{SExp::*, SLeaf::*, util::*}, + /// }; + /// + /// assert_eq!( + /// scons(Let, scons(var("x"), scons(1, Nil))).type_check(), + /// Ok(arr(vt("T"), vt("T"))) + /// ); + /// ``` + /// ie. the identity function. + /// + /// No more behavior on typing let can be defined, as typing the let-keyword + /// would require the yet untyped variable to be typed. + /// /// Though perhaps the most important task of the type system /// is to increase safety by being able to warn about errors /// before evaluation. Here are some failing examples: @@ -173,6 +210,7 @@ impl SExp { vecof(vt("T")), List(vec![VecType, vecof(vt("T"))]) )), + Atom(Let) => todo!(), SCons(op, l) => { -- cgit v1.2.3