Pass more tests

This commit is contained in:
Isaac Shoebottom 2025-03-26 14:26:41 -03:00
parent 64eb62a4d7
commit 9a5a5d683f

View File

@ -119,14 +119,16 @@
[(leqE l r) (num2 l r (boolT))] [(leqE l r) (num2 l r (boolT))]
[(varE s) (type-lookup s env)] [(varE s) (type-lookup s env)]
[(lamE name te body) (arrowT (interp-te te) (typecheck body (type-extend env name (interp-te te))))] [(lamE name te body) (arrowT (interp-te te) (typecheck body (type-extend env name (interp-te te))))]
[(appE fn arg) (typecheck fn env)] ; add proper handling for non functions [(appE fn arg) (type-case Type (typecheck fn env)
[(arrowT a b) (typecheck fn env)]
[else (error 'app "Function application must be a function")])]
[(ifE c t f) (if (equal? (typecheck c env) (boolT)) [(ifE c t f) (if (equal? (typecheck c env) (boolT))
(if (equal? (typecheck t env) (typecheck f env)) (if (equal? (typecheck t env) (typecheck f env))
(typecheck t env) (typecheck t env)
(error 'if "Both if conditions must be of the same type")) (error 'if "Both if conditions must be of the same type"))
(error 'if "Condition must be a boolean expression"))] (error 'if "Condition must be a boolean expression"))]
[(let1E var te val body) (arrowT (interp-te te) (typecheck body (type-extend env var (interp-te te))))] ; should be more returning type of lam, should just handle errors from application [(let1E var te val body) (typecheck body (type-extend env var (interp-te te)))]
[(recE var te val body) (typecheck body env)] ; add type binding for rec for use within same function, should be similar to let [(recE var te val body) (typecheck body (type-extend env var (interp-te te)))] ; figure out https://www.cs.unb.ca/~bremner/teaching/cs4613/docs/plai-3.2.2.pdf#page=132
))) )))
(tc : (S-Exp -> Type)) (tc : (S-Exp -> Type))