I need help with my interpreter's type system

🙋 seeking help & advice

I am relatively new to programming. and have read this article about making a clojure-like interpreter in rust. and i wanted to make one too

So. the thing i am on right now is about the type system (the second thing after the tokenizer)

i wanted the type annotations syntax to look like this (kinda like Haskell):

// fn and isize is builtin

fac :: fn isize -> isize

and as for setting the value

fac 0 | < 1 = 1

fac n = if n <= 0 then n else n * fac (n - 1)

list = [420,69]

and this is my "Types" system (which is just a bunch of enums)

// built in types
#[derive(Debug)]
pub enum HvllExpr {
// built in types
Void,
Symbol(String),
Int(isize),
Float(f64),
String(String),
List(Vec<HvllExpr>),
EvalFn(fn(HvllExpr) -> HvllExpr),
SetFn(fn(Rc<HvllEnv>, HvllExpr)),
}

And obviously. this wont work (for way too many reasons). and i am too dumb to think of a type system (or read the GHC's or rustc 's source code)

Guys. what should my type system look like?

Posted Nov 1, 2023, 4:04 PM UTC

43
Loading comments…