diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-06 14:15:12 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-06 14:15:12 +0300 |
commit | 23b2028bdce46d02209fc2df70fc5468a8beffa8 (patch) | |
tree | 31e7a6fae6d5d01759a84334555f4cd1fa26a038 /src/type/check.rs | |
parent | 3d7ebeddc46e89c8e058b3f1805f836339a2f9ae (diff) | |
download | myslip-23b2028bdce46d02209fc2df70fc5468a8beffa8.tar.gz myslip-23b2028bdce46d02209fc2df70fc5468a8beffa8.zip |
Added boilerplate and tests for let-binds
Diffstat (limited to 'src/type/check.rs')
-rw-r--r-- | src/type/check.rs | 38 |
1 files changed, 38 insertions, 0 deletions
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) => { |