I am working on a practice sheet for a final tomorow and I am a bit confused trying to figure out what the question is asking and how to resolve it. I wanted to check here and see if the good people of stack overflow can help me resolve it.
The question is set up like this:
Show a derivation tree (which is a trace of typecheck) demonstrating that the following expression has a type :
(appC (lamC ‘x ??? (plusC (idC ‘x) (numC 1)))
(numC 2) )
It is based on this definition of type check:
(define (typecheck [a : ExprC] [tenv : TypeEnv])
(type-case ExprC a
[numC (n) (numT)]
[plusC (l r) (typecheck-nums l r tenv)]
[multC (l r) (typecheck-nums l r tenv)]
[idC (n) (type-lookup n tenv)]
[lamC (n arg-type body)
(arrowT arg-type
(typecheck body
(extend-env (tbind n arg-type)
tenv)))]
[appC (fun arg)
(type-case Type (typecheck fun tenv)
[arrowT (arg-type result-type)
(if (equal? arg-type
(typecheck arg tenv))
result-type
(type-error arg
(to-string arg-type)))]
[else (type-error fun "function")])]))
(define (typecheck-nums l r tenv)
(type-case Type (typecheck l tenv)
[numT ()
(type-case Type (typecheck r tenv)
[numT () (numT)]
[else (type-error r "num")])]
[else (type-error l "num")]))
(define (type-error a msg)
(error 'typecheck (string-append
"no type: "
(string-append
(to-string a)
(string-append " not "
msg)))))
When I run this in racket :
(typecheck (appC
(lamC 'x (numT) (plusC (idC 'x) (numC 1)))
(numC 2))
mt-env)
I do get:
- Type
(numT)
- Type
(numT)
At the bottom it states :
"You check that the type for 'x must be : numT"
So it is coming up with numT but I am confused about the tracing part, I know this question is long but this is the one out of all of the practice questions that is confusing me the most. Any advice/help is appreciated